- Home /
Question by
asgerlolle13 · Jan 12, 2020 at 11:33 AM ·
pushing
How do i push an object?
How do i push an object? i use character controller
Comment
Answer by xibanya · Jan 14, 2020 at 10:11 PM
The objects you want to push should have rigidbody and collider components. In a component attached to your player with the CharacterController, have something like
void OnControllerColliderHit(ControllerColliderHit hit)
{
Rigidbody hitRigidbody = hit.collider.attachedRigidbody;
if (hitRigidbody != null && hitRigidbody.isKinematic == false)
{
hitRigidbody.AddForceAtPosition(hit.moveDirection * (characterController.velocity.magnitude / hitRigidbody.mass), hit.point, ForceMode.VelocityChange);
}
}
Your answer
Follow this Question
Related Questions
GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced) 0 Answers
how to make character controllers push eachother? 1 Answer
Stop Pushing 0 Answers
Pushing an object with parented origin HELP 0 Answers
Box pushes another box while it's supposed to move on top of it 0 Answers