- Home /
3DBuzz Platformer Tutorials - I can't get Jumping to Work
Hi guys,
This might be relatively long due to the code involved. I'm doing the Unity/C# free 3d platformer tutorials over on 3DBuzz and I'm up to the stage where you implement jump, fall, and land animations. In short - the problem is that it simply doesn't work.
My code is completely identical to theirs in every necessary way. Of course the names of animations are different and some things like that, but nothing that can affect anything.
I have rewatched the jumping/falling/landing videos over ten times each, there is no variation in relevant code, not a single bracket or capital is missed, or anything. And I'm freaking sick of rewatching videos that I've completed.
In it's current state the character jumps, the character falls, the character teleports to the ground and does not play a landing animation.
Pay attention to the Debug.Log lines, I put comments in those for testing purposes. There is this section of code here:
void Jumping()
{
Debug.Log("Here is the problem");
if ((!animation.isPlaying && TP_Controller.CharacterController.isGrounded) ||
TP_Controller.CharacterController.isGrounded)
{
Debug.Log("The above statement is NEVER true, it will never come here");
if (lastState == CharacterState.Running)
{
animation.CrossFade("LandRun");
Debug.Log("This will never happen");
}
else
{
animation.CrossFade("LandStationary");
Debug.Log("This will never happen, either");
}
}
else if (!animation.IsPlaying("JumpStationary"))
{
Debug.Log("This happens");
State = CharacterState.Falling;
animation.CrossFade("FallStationary");
}
else
{
Debug.Log("This does not happen either");
State = CharacterState.Jumping;
}
}
It doesn't make sense, their code works and mine doesn't yet their code is the exact same.
Can you see in the inspector what the value of isGrounded is. Also ''(!animation.isPlaying && TP_Controller.CharacterController.isGrounded) ||'' does not do anything and could as well be removed
I don't understand why they're doing that either. But it works for them. I can't see the value of isgrounded, not sure how to expose it either as it's a component of the charactercontroller, although i could have it print when the value changes, idk
Update; I made a mistake in my original question, the character does NOT play the jump animation, he only plays the falling animation, does not play landing either
Debug.Log("Here is the problem"); Gets printed every time you try to jump? (just making sure)
Answer by AlucardJay · Jul 07, 2012 at 09:35 AM
From memory (I did the tutorial a while ago now) there was some problems popping up for me too. There is a video right near the end called debugging, they fix up alot of the error that are in the project, so maybe watch that. (I fixed an error myself, and then got to the end an they said "you'll have to fix this", made me laugh. I'm not sure what video you are up to, so here's my Jumping function when it was completed/working.
void DetermineCurrentState()
{
if (MyState == CharacterState.Dead)
return;
// check if falling
if (!TP_Controller.myCharacterController.isGrounded)
{
if (MyState != CharacterState.Falling &&
MyState != CharacterState.Jumping &&
MyState != CharacterState.Landing)
{
// We should be falling at this point
Fall();
}
}
// check if not doing anything related to motion
if (MyState != CharacterState.Falling &&
MyState != CharacterState.Jumping &&
MyState != CharacterState.Landing &&
MyState != CharacterState.Using &&
MyState != CharacterState.Climbing &&
MyState != CharacterState.Sliding)
{
switch (MoveDirection)
{
case [ ....... ]
void Jumping()
{
if ((!animation.isPlaying && TP_Controller.myCharacterController.isGrounded) ||
TP_Controller.myCharacterController.isGrounded)
{
if (lastState == CharacterState.Running)
// running landing
animation.CrossFade("TPCperson1_JumpLanding");
else
// jumping landing
animation.CrossFade("TPCperson1_JumpLanding");
// set state to landing
MyState = CharacterState.Landing;
}
else if (!animation.IsPlaying("TPCperson1_Jumping"))
{
MyState = CharacterState.Falling;
// falling
animation.CrossFade("TPCperson1_Falling");
TP_Motor.Instance.IsFalling = true;
}
else
{
// jumping
MyState = CharacterState.Jumping;
// help determine if Player has fallen too far
}
}
@UnityAnswers why have you made posting code so damn difficult? and then change the finished product from that of the preview? #$@% !
I strongly recommend everyone does this tutorial for themselves,
this is only to be used as a reference for troubleshooting, O$$anonymous$$!
=]
here is my 'boxworld' demo, this is about the code, not the looks (biped is primatives animated in unity!). I have the terrain and puzzles too, but I re-wrote the tutorial in JS, so this is the last working version of C# I can find. Everything is there, including animations, fatal falling and climbing:
http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TPC_Boxworld_in_C.html
links to the C# scripts :
http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/ClimbingVolume.cs
http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/Helper.cs
http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TP_Animator.cs
http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TP_Camera.cs
http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TP_Controller.cs
http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TP_$$anonymous$$otor.cs
and just for a laugh : http://www.alucardj.net16.net/examples/TPC-tutorial/stand-ins.html
Cheers for doing that, huge help - unfortunately my code is identical where relevant and the problem still occurs. The thing is, that when I land, it does not detect that it's now grounded.
Unity knows I'm on the ground, but the code doesn't seem to realize it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613073821im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Project: Space Shooter - can't assign variable scoreText 5 Answers
How to code in coins 1 Answer
Script for Creating a VR Menu tutorial 0 Answers