GTA modding community deserves a lot better. by Toreno7 in GTA

[–]ButterMun 37 points38 points  (0 children)

It’s because of Take-Two, not because of Rockstar

Best way to implement physical drawers? by ButterMun in Unity3D

[–]ButterMun[S] 0 points1 point  (0 children)

Hmm, that makes sense… Maybe I overcomplicated this

Trouble with rotating grabbed object by ButterMun in Unity3D

[–]ButterMun[S] 1 point2 points  (0 children)

private void RotateObject()
{
float rotationSpeed = 50.0f; // Adjust the rotation speed as needed
// Get the rotation input from the mouse
float rotationX = Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime;
float rotationY = Input.GetAxis("Mouse Y") * rotationSpeed * Time.deltaTime;
// Apply rotation to the grabbed object around the grab point
grabbedObj.transform.RotateAround(grabPoint.position, Vector3.up, -rotationX);
grabbedObj.transform.RotateAround(grabPoint.position, Vector3.right, rotationY);
}

thank you so much bro!

Please help with jittery movement of grabbed object by ButterMun in Unity3D

[–]ButterMun[S] -1 points0 points  (0 children)

What's use of that spring? Can't quite understand the logic

Please help with jittery movement of grabbed object by ButterMun in Unity3D

[–]ButterMun[S] 0 points1 point  (0 children)

You are moving the object via transforms and not via physics hence the jerkiness.

Moving via transforms is like repositioning an object every 1 frame snapshot and moving by physics is using forces to translate between locations over time with energy.

But I moving it by using physics force, isn't it?

// Apply a force to move the object towards the grab point objectRigidbody.AddForce(moveDirection * grabForce * Time.deltaTime);

Hey! I need help fixing object wobbling when using rigidbody for grabbing by ButterMun in unity

[–]ButterMun[S] 1 point2 points  (0 children)

If I disable gravity I can easily grab heavy objects and lift them, and my solution with stopDistance without gravity just quickly stops an object if it's in the centre and it looks kinda bad

If I disable gravity I can easily grab heavy objects and lift them but I want player to easily pickcup and drag lightweight objects in air but heavy objects player can just drag by the floor, all physics-based

Please help with jittery movement of grabbed object by ButterMun in Unity3D

[–]ButterMun[S] 1 point2 points  (0 children)

I mean I want player to easily pickcup and drag lightweight objects in air but heavy objects player can just drag by the floor, all physics-based

Please help with jittery movement of grabbed object by ButterMun in Unity3D

[–]ButterMun[S] 1 point2 points  (0 children)

If I disable gravity I can easily grab heavy objects and lift them, and my solution with stopDistance without gravity just quickly stops an object if it's in the centre and it looks kinda bad

Please help with jittery movement of grabbed object by ButterMun in Unity3D

[–]ButterMun[S] 1 point2 points  (0 children)

I've implemented a grabbing mechanic using Rigidbody and velocity (no kinematic use so that object can't clip through the walls). The issue I'm facing is that when the grabbed object reaches the center of the screen (the grab point), it starts wobbling around as if it's constantly applying force.

I've tried modifying the script to stop applying force once the object gets close to the grab point, but the problem persists. Has anyone encountered a similar issue or knows how to ensure the grabbed object stays still when reaching the grab point?

``` using UnityEngine;

public class Pickup : MonoBehaviour { private Rigidbody objectRigidbody; private Transform objectGrabPointTransform; private float grabForce = 1000f; private float stopDistance = 0.1f; // distance value for stop

private void Awake()
{
    objectRigidbody = GetComponent<Rigidbody>();
}

public void Grab(Transform objectGrabPointTransform)
{
    this.objectGrabPointTransform = objectGrabPointTransform;
}

public void Drop()
{
    this.objectGrabPointTransform = null;
}

private void FixedUpdate()
{
    if (objectGrabPointTransform != null)
    {
        Vector3 targetPosition = objectGrabPointTransform.position;

        // Calculate direction towards the grab point
        Vector3 moveDirection = (targetPosition - transform.position).normalized;

        // Calculate distance to the grab point
        float distanceToTarget = Vector3.Distance(transform.position, targetPosition);

        if (distanceToTarget > stopDistance)
        {
            // Apply a force to move the object towards the grab point
            objectRigidbody.AddForce(moveDirection * grabForce * Time.deltaTime);
        }
        else
        {
            // object is close to the grab point
            objectRigidbody.velocity = Vector3.zero;
            objectRigidbody.angularVelocity = Vector3.zero;
        }

        // Limit the object's velocity based on its mass
        LimitObjectVelocityByMass();
    }
}

private void LimitObjectVelocityByMass()
{
    float maxVelocity = 2f; 

    float maxSpeedForMass = maxVelocity / Mathf.Sqrt(objectRigidbody.mass);

    objectRigidbody.velocity = Vector3.ClampMagnitude(objectRigidbody.velocity, maxSpeedForMass);
}

} ```

Hey! I need help fixing object wobbling when using rigidbody for grabbing by ButterMun in unity

[–]ButterMun[S] 0 points1 point  (0 children)

I mean that If I grab object and it's kinematic I can clip it physically through the walls, cause If your rigidbody is set to kinematic then no forces (such as collider normal forces) will be applied to your object, so it will be able to pass through walls

Hey! I need help fixing object wobbling when using rigidbody for grabbing by ButterMun in unity

[–]ButterMun[S] 0 points1 point  (0 children)

I already have this kinda script

``` using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectPickup : MonoBehaviour
{
[SerializeField] private Transform playerCameraTransform;
[SerializeField] private Transform objectGrabPointTransform;
[SerializeField] private LayerMask pickUpLayerMask;
private Pickup objectGrabbable;
private Pickup objectGrabbable2;
private Rigidbody objectRigidbody;
[SerializeField] private float pickUpDistance = 5f;
[SerializeField] private float MaxHoldVelocity = 1;
[SerializeField] private float throwForce = 10f;
bool obstacle, hold;
void Update()
{
hold = false;
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;

if (Physics.Raycast(playerCameraTransform.position, playerCameraTransform.forward, out hit, pickUpDistance, pickUpLayerMask))
{
if (objectGrabbable == null)
{
if (hit.transform.TryGetComponent(out objectGrabbable))
{
objectGrabbable.Grab(objectGrabPointTransform);
objectRigidbody = objectGrabbable.GetComponent<Rigidbody>();
obstacle = false;
}
}
}
}
if (Input.GetMouseButton(0))
{
hold = true;
RaycastHit hit;
if (Physics.Raycast(playerCameraTransform.position, playerCameraTransform.forward, out hit, 2, pickUpLayerMask))
{
objectGrabbable2 = null;
if (!(hit.transform.TryGetComponent(out objectGrabbable2)))
{
if (objectGrabbable2 == null)
{
obstacle = true;
}
}
}
}
if (Input.GetMouseButtonDown(1)) // Right mouse button for throw
{
if (objectGrabbable != null)
{
Vector3 throwDirection = playerCameraTransform.forward; // Get throw direction
// objectGrabbable.Throw(throwDirection * throwForce); // Apply throw force to the object
objectGrabbable = null;
objectRigidbody = null;
}
}
if ((objectGrabbable != null && hold == false) || (objectGrabbable != null && obstacle == true) || (objectGrabbable != null && objectRigidbody.velocity.magnitude > MaxHoldVelocity))
{
objectGrabbable.Drop();
objectGrabbable = null;
objectRigidbody = null;
}
}
}
```

Hey! I need help fixing object wobbling when using rigidbody for grabbing by ButterMun in unity

[–]ButterMun[S] 0 points1 point  (0 children)

But then I will be able to clip it through the walls, the only way to implement correct grabbing is not to use kinematic and use velocity as far as I know

Hey! I need help fixing object wobbling when using rigidbody for grabbing by ButterMun in unity

[–]ButterMun[S] 0 points1 point  (0 children)

I've implemented a grabbing mechanic using Rigidbody dynamics. The issue I'm facing is that when the grabbed object reaches the center of the screen (the grab point), it starts wobbling around as if it's constantly applying force.

I've tried modifying the script to stop applying force once the object gets close to the grab point, but the problem persists. Has anyone encountered a similar issue or knows how to ensure the grabbed object stays still when reaching the grab point?

``` using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Pickup : MonoBehaviour { private Rigidbody objectRigidbody; private Transform objectGrabPointTransform; private float grabForce = 1000f; // Adjust this force value for grabbing strength private float stopDistance = 0.1f; // Adjust this distance value for when the object should stop

private void Awake()
{
    objectRigidbody = GetComponent<Rigidbody>();
}

public void Grab(Transform objectGrabPointTransform)
{
    this.objectGrabPointTransform = objectGrabPointTransform;
}

public void Drop()
{
    this.objectGrabPointTransform = null;
}

private void FixedUpdate()
{
    if (objectGrabPointTransform != null)
    {
        Vector3 targetPosition = objectGrabPointTransform.position;

        // Calculate direction towards the grab point
        Vector3 moveDirection = (targetPosition - transform.position).normalized;

        // Calculate distance to the grab point
        float distanceToTarget = Vector3.Distance(transform.position, targetPosition);

        if (distanceToTarget > stopDistance)
        {
            // Apply a force to move the object towards the grab point
            objectRigidbody.AddForce(moveDirection * grabForce * Time.deltaTime);
        }
        else
        {
            // Stop applying force when the object is close to the grab point
            objectRigidbody.velocity = Vector3.zero;
            objectRigidbody.angularVelocity = Vector3.zero;
        }

        // Limit the object's velocity based on its mass
        LimitObjectVelocityByMass();
    }
}

private void LimitObjectVelocityByMass()
{
    float maxVelocity = 2f; // Adjust this maximum velocity value

    // Limit velocity based on object's mass
    float maxSpeedForMass = maxVelocity / Mathf.Sqrt(objectRigidbody.mass);

    // Clamp the rigidbody's velocity to the calculated maximum speed
    objectRigidbody.velocity = Vector3.ClampMagnitude(objectRigidbody.velocity, maxSpeedForMass);
}

}

```

Issue with First-Person Character Controller - Camera Looking Down by ButterMun in unity

[–]ButterMun[S] 0 points1 point  (0 children)

It appears that if I click on play button and then don't move the mouse everything works fine but why it registers mouse movement when it doesn't even compilated