Hello. I have a problem and was hoping someone could please help me out. I created different movement scripts for all of my characters to see if that would help in the event trigger, but it did not. Then, I made one script for all of the characters and added that in the event trigger, but they do not jump. All of the characters move left and right, but for some reason, they do not jump. Is there a certain way I should code the script to make all the characters be able to jump? I have buttons that control their movement, so I would need the event trigger. If anyone has any suggestions, or knows how to fix the problem, it would be greatly appreciated. Thank you in advance!
Sounds like you wrote a bug… and that means… time to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...);
statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
It also sounds like you’re working from a tutorial or example code. Keep this in mind:
Two steps to tutorials and / or example code:
- do them perfectly, to the letter (zero typos, including punctuation and capitalization)
- stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
If you do truly get stuck on a technical issue, this format is useful for reporting issues to complete strangers in a forum:
How to report your problem productively in the Unity3D forums:
This is the bare minimum of information to report:
- what you want
- what you tried
- what you expected to happen
- what actually happened, log output, variable values, and especially any errors you see
- links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?
If you post code, only post the relevant code and always use the format button above. Do not post photographs of code.
I actually did a Debug.Log and it says player is jumping when I press the jump button.
What should I do to make it work? It says the player is jumping even when it’s not really jumping.
I’m surprised you didn’t say also,
“I debugged the velocity before and after the application of the force and also printed out the force and it was a reasonable value…”
This isn’t going to debug itself. You’re the one who has to debug it.
See above.
I added a Debug.Log in the function that has that code, and it still doesn’t work. It’s still saying the player is jumping for some reason.
maybe it’s because of your jump logic, show us your code
As already noted above, that’s not how to post code if you want someone to actually comment meaningfully on it or correct it.
Per forum rules:
Again, when you’re ready to actually receive help, I strongly suggest following this format:
How to report your problem productively in the Unity3D forums:
This is the bare minimum of information to report:
- what you want
- what you tried
- what you expected to happen
- what actually happened, log output, variable values, and especially any errors you see
- links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?
Is there anything I should fix in the code?
Again, as I already posted above, debugging is how you can find out what is wrong.
Hint: we don’t know what is wrong and we cannot debug your code.
I put the Debug.Log in the code and it showed it in the console even though the character wasn’t jumping.
if these problems occur, as my friend above said you should debug, and it’s not only in putting debug.logs, try to start over with only essential code lines, so in your case remove animator lines and remove the bools and remove the addForce with the rb2d.gravityScale and only leave it like this:
Public void ChJumpButton()
{
rb2d.AddForce(Vector2.up * Jumpforce, ForceMode2D.Impulse);
}
and see if the player is jumping, And make sure that: rigid body mass is reasonable like 1 - 10, rigid body is not constrained and is not kinematic, and jump force with reasonable value (try 10 - 1000).
Good luck.
Ok. Thank you! I’ll try that.
I tried what you suggested, but the characters still won’t jump.
well I can’t help you in this case.
why don’t you try following a tutorial step by step and see if there’s anything missing.
hope you resolve the issue soon.
Thank you for the suggestion and for all your help! I’ll keep trying to figure it out. Hope you have a great day.