Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Vire · Jul 07, 2012 at 03:03 AM · c#tutorial

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.

Comment
Add comment · Show 14
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Linus · Jul 07, 2012 at 04:05 AM 0
Share

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

avatar image Vire · Jul 07, 2012 at 04:50 AM 0
Share

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

avatar image Vire · Jul 07, 2012 at 06:23 AM 0
Share

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

avatar image Linus · Jul 07, 2012 at 07:33 AM 0
Share

hmm could you post your declaration of TP_Controller

avatar image Linus · Jul 07, 2012 at 07:46 AM 0
Share

Debug.Log("Here is the problem"); Gets printed every time you try to jump? (just making sure)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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? #$@% !

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Jul 07, 2012 at 10:51 AM 0
Share

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

avatar image Vire · Jul 07, 2012 at 12:19 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges