Hello. I made a simple player control script.
And this is what I use to jump:
if (Input.GetButton("Jump"))
{
GetComponent<Rigidbody>().velocity += new Vector3(0, jumpSize, 0) + transform.forward * 2f;
}
I want to make it so that whenever you walk, you would jump in that direction that you are walking, but current one I got only works for whatever you are facing, so if I go backwards and jump, it jumps forward.
Sorry I accidently posted this thread early.
So as I said, I want it so that whenever you go right, but you are facing front, it will jump right, like a regular jump that is used in most games.
jumpSize is a float.
Any ideas on how to do this?
if (Input.GetButton("Jump"))
{
// add condition here where you facing
If(facing="right"){
GetComponent<Rigidbody>().velocity += new Vector3(0, jumpSize, 0) + transform.forward * 2f;
}
If (facing="left"){
GetComponent<Rigidbody>().velocity += new Vector3(0, jumpSize, 0) + transform.backward * 2f;
}
}
You could do this check in the Update Function, and set the string facing to left or right, whenever you tap the jump button then it checks your facing direktion and moves you left or right