Hello everyone,
I trying to create a simple VR Hockey Goalie game. Right now I am working on the script for puck movement. The players will always remain stationary. When it is their turn to shoot they will pick a random spot on the net and shoot there. My net has a box collider, which I am referencing in a script called ScoreDetect attached to the net. This function gets a random location within the box collider (net) bounds.
Here is the function/code for that. If you see anything wrong please let me know:
(netArea is referring to the box collider)
public Vector3 RandomNetArea()
{
float y = Random.Range(netArea.bounds.min.y, netArea.bounds.max.y);
float z = Random.Range(netArea.bounds.min.z, netArea.bounds.max.z);
Vector3 shootSpot = new Vector3(transform.position.x, y, z);
return shootSpot;
}
Next is the actual puck movement, which has a script attached to the puck prefab. For the movement function, I am referencing the RandomNetArea() function from the other script and storing the Vector3 that it returns into a new Vector3 called shootSpot as well. I simply get the rigidbody of the puck and add force to it with the location:
void ShootPuck()
{
Vector3 shootSpot = scoreDetect.RandomNetArea();
rb.AddForce(shootSpot * speed);
}
As of now, the rigidbody of the puck has a mass of 0.5 and uses gravity. The problem is that the puck is always shot straight at the net and does not get off the ground. When I uncheck use gravity the puck does get off the ground a little more, but then it hovers and that isn’t very realistic. Is there another way that I should be doing this, or am I missing something? Thanks for all of your help in advance.