Hello. I have been coding for my game for a little while now. I am making my own player controller but have come to a stop. I can’t figure out how to make it jump? I have it set so when I press the space bar it goes up 1 meter in the Y axis, and it isn’t working. I can’t figure it out and I am still learning to code, but all of tutorials are in JS and I’m using C#. Do I need to AddForce onto a Rigidbody or maybe have some velocity?
Hmm, I tried something else and it worked fine for me except that you could I guess infinity jump type of thing. I am using it for 3D and not 2D and your code didn’t allow me to jump, so I’m supposing it doesn’t work for 3D games. But anyway do you know of anything that would allow me to only have single jumps and not infinite jumps?
my bad, it was for 2D I did not used 3d, but i think, it can be for 3d:
rigidbody.AddForce(new Vector3(0, 1000, 0));
against infinity jump:
it’s not only one way to achive that.
i think, it is easy, but not the best, if you make jump time dependet with boolean + if. Something like:
float JumpPause;
public float MaxJumpPause = 1;
bool JumpNow;
void Start ()
{JumpPause = MaxJumpPause; }
void Update ()
{
if (!JumpNow)
{ JumpPause -= Time.deltaTime;
if (JumpPause < 0)
{ JumpPause = MaxJumpPause;
JumpNow = true;}
if (Input.GetKeyDown (KeyCode.Space) && JumpNow)
{ //here your script for jump ?? rigidbody.AddForce(new Vector3(0, 1000, 0)); ??
JumpNow = false;}
}
or you make boolean and check ground under player. May be with collider. But as said i cannot 3d