In my scene I have a player and a ball that is dropping when ever I hit play in editor.
When I’m controlling the player and collide with the ball before it drops, it moves. However, if the ball hits the ground before the player comes into contact with the ball then the player would not be able to move the ball with physics and passes right through the ball.
How can I fix this to have the ball move. I would appreciate any help.
Word to the wise: It’s generally a good idea to post details of how your objects work and what components they have so that other people can help isolate the problem.
However, I believe I have been able to reproduce your issue. In my scenario, the ball has a collider and an active Rigidbody. The player has a collider but no Rigidbody, and a controller script that moves the player using transform.Translate. If this is the case, then the ball can still fall onto the player while it has velocity. However, once the ball is still, it requires ‘mass’ to push it around, necessitating either adding a rigidbody and mass to the player or using OnColliderEnter in the player script to manually add force and movement to the ball. For example:
private void OnCollisionEnter(Collision collision)
{
Vector3 power = 5f;
Vector3 direction = transform.position - collision.transform.position;
collision.gameObject.GetComponent<Rigidbody>().AddForce(power * direction);
}
I hope this helps!
Hi @The_Three_Vs , I just saw this since I haven’t been on since the past two days. Thank you for the info! I will definitely give this another try.