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 oquendo · Apr 18, 2011 at 10:52 AM · movement

Movement script

I'm trying to wrap my mind around the Platformer controller script from the 2d Platformer tutorial, but I have some doubts I don't seem to be able to solve by reading the script and reference manuals. Here goes. On this piece of code:

function ApplyJumping () { // Prevent jumping too fast after each other if (jump.lastTime + jump.repeatTime > Time.time) return;

if (controller.isGrounded) { // Jump // - Only when pressing the button down // - With a timeout so you can press the button slightly before landing
if (jump.enabled && Time.time < jump.lastButtonTime + jump.timeout) { movement.verticalSpeed = CalculateJumpVerticalSpeed (jump.height); movement.inAirVelocity = lastPlatformVelocity; SendMessage ("DidJump", SendMessageOptions.DontRequireReceiver); } }

}

I don't get what the

if (jump.enabled && Time.time < jump.lastButtonTime + jump.timeout)

bit does. The variables are pretty self-explanatory, (jump is a custom class with a number of variables, timeout is a constant previously set at 0.15)

To me this looks as if jumping will only occur if the button is pressed before timeout time has passed after it was pressed last time. Which doesn't make sense (I can only jump if I keep jumping?). I'm sure I'm missing something, I just can't find out.

Please let me know if you need more details.

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
Best Answer

Answer by Uzquiano · Apr 18, 2011 at 11:06 AM

Well, you are right, take a look t othe comment ' With a timeout so you can press the button slightly before landing' so in case you are not still grounded you can jump again...

but i am sure there is another part of code where you can jump when you are grounded :)

Comment
Add comment · Show 5 · 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 oquendo · Apr 18, 2011 at 11:18 AM 0
Share

Yes, but this code seems to apply if you're grounded. (See the if (controller.isGrounded)), so how does that comment make sense?

avatar image oquendo · Apr 18, 2011 at 11:30 AM 0
Share

I mean, of course, the script comment, not yours :D

avatar image Uzquiano · Apr 18, 2011 at 11:36 AM 0
Share

Yep, sorry I didn't explian myself properly, if you are grounded but if you pressed before landing, the pressed button is still efective, so you can jump again...

Did I explain me better ?... Think about yourself playing games... you press jumpling before landing... but the character doesn't jusmp til grounded...

avatar image oquendo · Apr 18, 2011 at 11:53 AM 0
Share

O$$anonymous$$, so if timeout hasn't yet passed, you can press 'jump' again. But not all jumps last the same (if you hold jump, you jump higher), and timeout is still the same. Does that mean that for longer jumps, the button becomes active earlier?. Also, I've searched the cript and found no other call to the DidJump or CalculateJumpVerticalSpeed functions. The game works though...

avatar image oquendo · Apr 18, 2011 at 02:15 PM 0
Share

Still not sure about this. I can't find any other function that performs the jumping, apart from this, and I can't see how this one does the job...

avatar image
0

Answer by oquendo · Apr 18, 2011 at 02:44 PM

I found this, which I think is what applies the initial upwards speed to start the jump (in particular the else if statement).

if (extraPowerJump)
        return;
    else if (controller.isGrounded)
        movement.verticalSpeed = -movement.gravity * Time.deltaTime;
    else
        movement.verticalSpeed -= movement.gravity * Time.deltaTime;

However, I still don't understand the minus sign?

-movement.gravity * Time.deltaTime

Wouldn't that result in a downwards speed? (gravity is stated at the top of the script as

var gravity = 60.0;

)

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

No one has followed this question yet.

Related Questions

funky rigidbody movement 0 Answers

The referenced script on this behavior is missing! 2 Answers

Variable Script "movement" 2 Answers

Movement in my terrain ? 2 Answers

Airplane Script Control 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