- Home /
problem with rigidbody.AddRelativeForce
I'm getting a weird problem when applying a force to an object. When I have the object highlighted in the Scene window as I run the game it acts as expected. Whey I do not have the object highlighted it flies off in an unexpected direction.
The objecte is ball. When the player is dribbling, i stick the ball to the player's feet using (in Update on the ball):
if (controllingPlayer)
{
transformLocation = controllingPlayer.transform.Find("BallPosition");
transform.position = transformLocation.position;
transform.rotation = transformLocation.rotation;
}
When I want to shoot the ball I call a function on the ball (Called from Update on the player):
function Shoot ()
{
controllingPlayer = null;
rigidbody.AddRelativeForce (Vector3(0, .1, 1) * shotForce, ForceMode.Impulse);
}
The weird thing is it fires off in the direction the player is heading when the ball is highlighted in the editor. It flies downwards through the ground plane when the ball is not hightlighted when the program is executed.
Your answer
Follow this Question
Related Questions
Problem with rigidbody rotation 2 Answers
How do I make my character's speed stay consistent? 0 Answers
Sphere movement very erratic and uncontrollable. 1 Answer
Rigid body rotation question 1 Answer