I am currently developing an Air hockey game in Unity3d. The problem that I encounter is that when a player tries to hit the puck too quickly, the player enters through the puck and therefore no collision occurs. The game works perfectly as expected if the player remains stationary and the puck hits the player or if the player scores the puck at a slow pace.
The player has a rigid body using continuous collision detection using the capsule collider. The puck also has a rigid body with continuous dynamic collision detection and a mesh collider with a convex.
I tried to set a fixed time interval to 0.01, but this did not affect. Here is the script for player movement:
void ObjectFollowCursor() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 point = ray.origin + (ray.direction * distance); Vector3 temp = point; temp.y = 0.2f;
and here is the puck code when it collides with the player:
// If puck hits player if(collision.gameObject.tag == "Player") { Vector3 forceVec = this.GetComponent<Rigidbody>().velocity.normalized * hitForce; rb.AddForce(forceVec, ForceMode.Impulse); Debug.Log ("Player Hit"); }
Any help would be greatly appreciated. Thank you
source share