I am a newbie trying to making a soccer game with Unity3D. The ball has a rigidbody attached and is moved using AddForce.
I have added a ‘swerve’ effect to the ball by enabling the user to AddForce to the ball with the input keys for one second following each kick. For example, if the ball is kicked directly ‘up’ the screen and then the left key is held down, the ball moves to the left simulating a swerve.
This is working well, but it adds speed to the ball when I only want the input to change the ball’s direction. So if the ball is kicked directly ‘up’ the screen and the ‘up’ key is held down, the ball travels further than I want it to because speed is being added. Ideally I want there to be no effect at all in this scenario, because the direction wouldn't be changed.
So my question is: how can I add direction only to the rigidbody without altering the speed?
Here is how I am adding swerve in FixedUpdate():
if (shallApplySwerve) // shallApplySwerve is true for 1 second after a kick
{
Vector3 inputV3 = new Vector3(matchInputManager.Input.x, 0, matchInputManager.Input.y); // create a Vector3 from input
Vector3 swerveForce = swerveCapability * inputV3; // swerveCapability is a float to determine how much swerve to add
rb.AddForce(swerveForce, ForceMode.Impulse);
}
Any help would be appreciated.
↧