#How does RigidBody3D.ApplyForce/ApplyCentralForce work exactly?

1 messages · Page 1 of 1 (latest)

pallid flicker
#

I'm trying code an object grabbing system similar to Half life 2's grabbing system, using the object's LinearVelocity property gives me what I'm looking for. However I understand I should not be modifying it every frame, so I am attempting to use the ApplyCentralForce method instead.

Using the ApplyForce methods cause the object to whip around the target position however, instead of staying at the position like LinearVelocity did.
Could I get some help with making the ApplyCentralForce method work the same as using LinearVelocity?

#
        if (Input.IsActionJustPressed("interact"))
        {
            if (interactRay.IsColliding() && interactRay.GetCollider() is RigidBody3D body && heldObject == null)
            {
                heldObject = body;
            }
            else if (heldObject != null)
            {
                heldObject = null;
            }
        }

        if (heldObject != null)
        {
            Vector3 targetPosition = interactRay.ToGlobal(interactRay.TargetPosition);

            heldObject.ApplyCentralForce((targetPosition - heldObject.GlobalPosition) * 30f);
        }```