Doubt about vector3 normalization direction.
Hi all, I'm trying to create a shoot system for a football prototype. I'm starting with very basic IA behaviours working in a State Machine. Unfortunately, I'm having problems with the shoot state direction. My current objective is to make the player always shoot at the center of the goal, but this only happens if the ball is centered towards the goal, if I change the ball position for one side or the other, the normalized direction presents a slight variation for that side. To check if the normalized vector was right, I end up using Debut.Ray and the ray is actually pointing at the center of the goal, so I can't understand what is making the shoot vary based on the ball position.
Will try to sum up my codes here:
Shoot state script:
var finalShootDirection = (shootTarget - ballController.ballPosition).normalized;
Debug.DrawRay(ballController.ballPosition, finalShootDirection * 30, Color.cyan, 5);
ballController.AddForceToBall(finalShootDirection, shootPower);
BallController's AddForceToBall method only has this:
public void AddForceToBall(Vector3 ballDirection, float power)
{
ballRB.AddForce(ballDirection * power);
}
To illustrate things better, there are 2 images below:
Answer by gabrimo · Aug 28, 2019 at 02:29 PM
The problem is that the player who touches the ball apply a very small amout of force because of the collision itself, that force is what was causing the little distortion in the shoot direction.
Your answer
Follow this Question
Related Questions
c# help with rotate and rotatearound 0 Answers
iron sight using inverse kinematic 0 Answers
How to disable diagonal Vector3 movement of non-player object using MoveTowards? 1 Answer
prob to define a condition to get out of a search position loop for obstacle avoidance 0 Answers
Creating a new vector3 2 Answers