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 dail · Aug 02, 2014 at 08:08 PM · physicsjumpitween

Itwen MoveTo - jump

Hello everyone. I'm using ITween, iTweenPath to make a car following a path. I want the car jump when you press the space button, but I can not. Can anyone help?

 void Start () {
         iTween.MoveTo(gameObject, iTween.Hash("path", iTweenPath.GetPath("pathteste"), "time", 10,"easetype",iTween.EaseType.linear, "orienttopath", true));
     }
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

1 Reply

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

Answer by robertbu · Aug 02, 2014 at 08:17 PM

One solution is to make the visual car a child of an empty game object at the same position. You use the empty game object in the iTween call. You implement the jump in a separate script attached to the car that changes the car's transform.localPosition. Something like:

 #pragma strict
 
 public var jumpHeight : float = 0.75;
 public var jumpTime : float =     0.8;
 private var jumping = false;
 
 function Update () {
     if (!jumping && Input.GetKeyDown(KeyCode.Space)) {
         Jump();
     }
 }
 
 function Jump() {
 
     jumping = true;
     var timer : float = 0.0;
 
     while (timer <= jumpTime) {
         var height : float = Mathf.Sin(timer / jumpTime * Mathf.PI) * jumpHeight;
         transform.localPosition = Vector3(0, height, 0);
         timer += Time.deltaTime;
         yield;
     }
 
     transform.localPosition = Vector3.zero;
     jumping = false;
 }
Comment
Add comment · Show 3 · 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 dail · Aug 02, 2014 at 08:45 PM 0
Share

It worked but not exactly. The object follows the path but when I press the button, it disappears from where it is, appears at the starting point, jumps, disappears from the start point and appears again where you pressed the button and continue the path. I do not know if what I said was clear but that is what is happening

avatar image dail · Aug 02, 2014 at 08:53 PM 0
Share

Thank you very much. Now it works perfectly. Just did a change in the code:

 while (timer <= jumpTime) {
         float height = $$anonymous$$athf.Sin(timer / jumpTime * $$anonymous$$athf.PI) * jumpHeight;
         transform.localPosition = new Vector3(transform.localPosition.x, height, 0);
         timer += Time.deltaTime;
         yield return 0;
     }
avatar image robertbu · Aug 02, 2014 at 08:59 PM 0
Share

There is some setup error if you are having the problem you claim. The most likely problem is that you did not setup the empty game object and the visible game object to be in the same place. That is, the position of your visible, child object should be (0,0,0) in the editor since the editor shows the local position of an object. And then you need to revert to my code. In addition you should use:

  yield return null;

...for C#.

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

2 People are following this question.

avatar image avatar image

Related Questions

The player doesn't jump to the left with the W key pressed 0 Answers

integrating itween with physics 1 Answer

How to make objects "Bounceable" 1 Answer

Problem with joints 2 Answers

Wall Jump Scripting Help 2 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