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 smirlianos · Aug 06, 2013 at 01:07 PM · timelerpoffsetmathfdeltatime

Jump with mathf.lerp problem

Hello,

i want my player to jump using mathf.Lerp.

I already managed to make him jump, but he doesn't fall again. What's wrong with my script?

 function Update () {
     
     transform.Rotate(0,0,Input.GetAxis("Horizontal") * speed * Time.deltaTime);
     player.transform.localPosition.y = newPos;
     if(Input.GetKeyDown(KeyCode.Space))
     {
         jumping = true;
     }
     if(jumping)
     {
         Jumper();
     }
 }
 
 function Jumper () {
     timer += Time.deltaTime * jumpSpeed;
     timerFall += Time.deltaTime * jumpSpeed;
     newPos = new Mathf.Lerp(startPos, startPos + jumpHeight, timer * jumpSpeed);
     yield WaitForSeconds(0.5);
     newPos = new Mathf.Lerp(startPos + jumpHeight, startPos, timerFall * jumpSpeed);
 }
Comment
Add comment · Show 1
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 smirlianos · Aug 06, 2013 at 01:33 PM 0
Share

Any help?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Xtro · Aug 06, 2013 at 04:01 PM

you don't cancel the jumping by setting the jumping = false;

instead of if check, just use this:

jumping = Input.GetKeyDown(KeyCode.Space);

this will set it true or false according to space key.

Comment
Add comment · Show 4 · 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 smirlianos · Aug 06, 2013 at 04:15 PM 0
Share

Where should I put this line?

avatar image Xtro · Aug 06, 2013 at 04:16 PM 0
Share

ins$$anonymous$$d of this part:

 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
 {
    jumping = true;
 }
avatar image Xtro · Aug 07, 2013 at 01:46 PM 0
Share

did it help?

avatar image smirlianos · Aug 07, 2013 at 03:52 PM 0
Share

Now it doesn't work even the 1st part of the jump!

avatar image
0

Answer by tamimsaiyed · Sep 05, 2015 at 04:17 PM

Ok, this is a really old post, and you've probably already figured it out by now, but since you are using: yield WaitForSeconds(0.5); Shouldn't your Function be written as: function Jumper() : IEnumerator { ...... } and your Function call as: if(jumping) { StartCoroutine(Jumper()); } ???

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 Xtro · Sep 05, 2015 at 04:50 PM 0
Share

He's using javascript. Not C#. In javascript(UnityScript actually) you don't need to define IEnumerator type for the function.

avatar image tamimsaiyed · Sep 05, 2015 at 05:09 PM 0
Share

Oh ok, my bad then, recently changed some C# code into JavaScript and kept IEnumerator type as a precaution, so thanks for the update.

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

16 People are following this question.

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

Related Questions

how to use time on lerp 2 Answers

Time.deltaTime making color lerp appear fast, but won't reach 1 1 Answer

Trying to lerp in different states in a switch statement 0 Answers

Mathf.Lerp Question 2 Answers

Execute code every x seconds with Update() 4 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