Push the objects when collide with other object
Hi,
I am trying to resolve the issue that I am facing. I want to rotate the object in any direction with same effect as the football moves when player hit the football.
I have found this Code useful but it works with FPSController. But In my case it is not FPSController, it's the simple GameObject that pushes the other GameObject.
public class ExampleClass : MonoBehaviour {
public float pushPower = 2.0F;
void OnControllerColliderHit(ControllerColliderHit hit) {
Rigidbody body = hit.collider.attachedRigidbody;
if (body == null || body.isKinematic)
return;
if (hit.moveDirection.y < -0.3F)
return;
Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);
body.velocity = pushDir * pushPower;
}
}
If I do this code in OnCollisionEnter, OnCollisionStay then I did not get the moveDirection Vector. Anyway to achieve this?
Thanks in advance.
Your answer
Follow this Question
Related Questions
Rotate object to joystick and position direction 0 Answers
How can I incorporate a Rotation Towards the Mouse Position into this Script? I Tried. 0 Answers
Why does my object's position change when I rotate it? 0 Answers
How do I rotate my object back to the world's up direction whilst keeping it's forward direction? 0 Answers
Virtual camera odd behaviour. Scriptting noob questions 0 Answers