- Home /
Player character moves without controller input
Hi. Very grateful for any insight anyone may be able to provide.
I am creating a space fighter type game. The controller input is a standard joystick and it works fine although quite often the player game object floats up on its own, without controller input.
The code I have used is below:
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("LeftThumbX");
float moveVertical = Input.GetAxis("LeftThumbY");
float boost = Input.GetAxis("RightTrigger");
Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);
//This is a boost and brake function
if (boost > 0)
{
movement *= boostMovementSpeed;
body.velocity = movement;
}
else if(boost < 0)
{
movement *= brakeMovementSpeed;
body.velocity = movement;
}
else
{
movement *= moveSpeed;
body.velocity = movement;
}
Do you have deadzone for your analog thumbs? Debug moveHorizontal and moveVertical values.
From the docs on Rigidbody.velocity:
In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour. Don't set the velocity of an object every physics step, this will lead to unrealistic physics simulation.
Answer by swanne · Oct 24, 2017 at 09:47 AM
Hi @TanselAltinel thank you for taking the time to comment.
Yes, I have dead zones setup for the controller and have used Debug.Log to measure the input. Both horizontal and vertical are at zero.
I'm still very confused
Well then, I think it may have to do with vector cross product where you are multiplying movement with boost$$anonymous$$ovementSpeed and brake$$anonymous$$ovementSpeed, can you debug the latest velocity in each case of if else? Because I believe that's the part setting it to a go ins$$anonymous$$d of horizontal/vertical inputs.
Answer by m00per · Jan 08, 2018 at 09:01 PM
I had a similar problem and it took me a while to realise that I still had vJoy (Joystick simulator) installed and removing it fixed it for me.