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
0
Question by Cello · Jul 20, 2012 at 04:40 PM · jumpy-axisfallmovedirection

Falling down the Y-axis?

Hello,

At the moment i'm refining my character movement script (and my very first script ever) which uses a character controller. The question I have is, is there perhaps a way to detect if the character is moving down a certain axis?

I ask because I have the jump set up just fine, but I would like my character to switch into a falling animation if he starts moving down the Y axis until the character is grounded. I've looked around at other scripts with a fall applied but they don't seem to be what i'm looking for.

I'm using moveDirection.y for the jump translations. Here's a snippet of the jump part of my code (minus the animation section):

 if (Input.GetButton("Jump"))

{ moveDirection.y = jumpSpeed; } } //Apply gravity moveDirection.y -= gravity * Time.deltaTime;

Or is there maybe a better way i'm not thinking of to detect a fall?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Jul 20, 2012 at 05:10 PM

You could save the position from frame to frame, subtract current from last (divide by delta time if you like) and see what the Y component looks like. Or use rigidbody's velocity component. You want to see that y is in the negative direction (positive would be a jump)

Comment
Add comment · Show 1 · 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 Ubahs · Apr 14, 2013 at 10:45 AM 0
Share

Thank you for mentioning the rigidbody's velocity component. I was going insane trying to get a falling setup, but the gravity subtracting from y was making it almost impossible to go by that route. Hours of fiddling turned into:

  if (this.playerController.velocity.y < 0)
avatar image
1

Answer by Meater6 · Jul 20, 2012 at 05:15 PM

I would think that the jump code would be irrelevant, because for example, the character just walks of a cliff without jumping, it would not play the falling animation. I would just use the character controller's collision flags or the isGrounded function to see if the controller is in the air. I would also check to see if the y component of the velocity is negative. If, as in some cases, your character should be playing the fall animation, but is not moving down, I would make a variable to store whether the character is "falling" (a.k.a. in the air & not jumping). If this is true, play the falling animation.

If this is your first script ever, it sounds very impressive. In case you don't know the scripting reference, here it is.

Good luck.

Comment
Add comment · 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

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

Another Slow Fall Problem... 2 Answers

the ball falls in a straight line sloping 0 Answers

Jumping script WONT WORK!!!!!!!! for 2D 1 Answer

My character does not go forward when I jump? 0 Answers

Falling Damage 1 Answer


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