Hello, I'm currently trying to make a 2D platformer game, and I'm consistently having a problem with the jumping that does not seem to come up in tutorials in that my player object does not go up and then go back down. Instead, the object teleports a distance, and then falls back down. I also have a variable to track if the player is grounded or not, which is working fine. So, what I'm wondering is, why is my code teleporting the object instead of moving the player? Another thing I'm confused about as well is that when I try to translate the code for moving left and right, which can be seen right above Jump being called in FixedUpdate, to code to jump, it will still teleport me even though the same code that moves the object left and right is smooth.
Have you tried calling your jump function into an Update() rather than the FixedUpdate? Try that and lemme know what happens.
When I call the Jump function in an Update, nothing happens when I press the space bar. I put in a Debug log to see if it was being read, and it is, so it is being read.
Did you move all of your code into an Update() or just the Jump() function? I'm also curious about what happens when you press "W" or "S" using this code. I would imagine "Horizontal" would default those keys to work as well. Which may not be what you want. Worth a test, no?
Just curious, what will happen, when you remove rigidBody velocity line.. will you still just teleport instead jumping?
I moved all of my code from the Jump function to the Update function. Nothing is currently calling the Jump function. Also, the W and S keys do not do anything. "Horizontal" refers to left and right, and defaults to A and D. So with this code currently, they do not do anything. I do not 100% understand what you're saying. Do you mean remove the "velocity" part that is part of the line "rb2d.velocity = movement * speed"?
You call rb2d.AddForce in Jump(), then in FixedUpdate() you set the rb2d.velocity = movement * speed; AddForce changes the velocity over time, but you are overwriting it in FixedUpdate(). Try: Code (CSharp): rb2d.velocity += movement * speed;
This has worked perfectly now. Thank you so much. I had tried += with many different methods, however, it never occurred to me that they were all having to do with Vectors so it didn't work.