- Home /
The question is answered, right answer was accepted
How to add a force to a falling object
I have a player with a charater controller and i want to push an object ( with rigidbody) if the object its falling .
void OnControllerColliderHit(ControllerColliderHit hit) {
Obiect obiect = hit.collider.GetComponent<Obiect>();
Rigidbody body = hit.collider.attachedRigidbody;
if (body == null || body.isKinematic)
{
return;
}
if (hit.moveDirection.y < -0.3)
{
return;
}
Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);
if (obiect != null && obiect.isFalling == true )
{
Debug.Log("Merge");
//here i want to apply the push
body.AddForce(hit.point * thrustForce , ForceMode.Impulse );
}
if (MasaPlayer > body.mass )
body.velocity = pushDir * pushPower;
}
you are adding force to the body already, did you want to also add force to the object? just insert object instead of body? other.AddForce(hit.point thrustForce , ForceMode.Impulse ); if you want it to go in the opposite direction you can it by new Vector(-1,0,0); or whatever direction you want.
thanks for pointing the problem . i've solved it , i just added another condition to the last if and i've moved the applyed force in the update .
Follow this Question
Related Questions
RigidBody.MovePosition seems jerky in movement 0 Answers
Trace 3D Basketball Shot 1 Answer
Fps Movement Velocity Decrease 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers