So here is the context: I’m making a little Airhockey game, where the player controls the pusher by moving the mouse. I got it working by the following “pseudo-code”:
transform.position = mousePosition;// i.e. pusher's position = mouse position, where I mouse position is gotten with Camera.main.ScreenToWorldPoint , no problem on that
Now comes my problem: If the mouse is moved too quickly, it happens that the pusher can find itself inside the puck, and for some reason, not colliding with it.
Here is my collision script:
private void OnCollisionStay(UnityEngine.Collision collision)
{
if (collision.gameObject.GetComponent<MouseMove>() != null) {
direction = transform.position - collision.contacts[0].point;
GetComponent<Rigidbody>().AddForceAtPosition(direction*2, collision.contacts[0].point, ForceMode.Impulse);
}
}
(By the way I just made a custom collision so I can adjust the bouncing power freely)
So that’s quite it, I would like to know if there is a way to make the pusher move instantly to the wanted position, but by actually moving, not teleporting (because I believe this is the main reason to my problem)
Or if my custom collision function is somehow incomplete.
Here is a screenshot of the “bug”: