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 Saraki · Mar 17, 2013 at 03:54 PM · rotationjavascriptjump

How to make a jump and a rotation using javascript?

Hello, I am a rookie in unity i was trying to make a moving car, I am using the following command in javascript to make it "jump n rotate" but the movement is irregular and sometimes it even ends up piercing right through my terrain please help!Am i writing something wrong ??

**if (Input.GetKey (KeyCode.Space) ) { transform. Rotate ( rotation_speed*Time.deltaTime, 0.00 , rotation_speed*Time.deltaTime);
transform.Translate (Vector3 (0.00, 3.00,0.00) Time.deltaTime*5.00); }*

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
0

Answer by robertbu · Mar 18, 2013 at 06:20 AM

You've not explained much about your project, but since you write "piercing right through my terrain," I'm guessing you have a Rigidbody. Typically Rigidbodies need to be moved through force, not transform.Translate() and transform.Rotate(). For exmaple:

 rigidbody.AddForce(Vector3.up*upForce*Time.deltaTime);
 rigidbody.AddTorque(Vector3.up*angularForce*Time.deltaTime);

Note how much force you need will depend on the mass of the object. If your car does not seem to move, greatly increase upForce and angularForce.

If instead you have a character controller, take a look at CharacterController.Move() and CharacterController.MoveSimple().

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
avatar image
0

Answer by Saraki · Mar 18, 2013 at 05:49 PM

Thank you for your answer robertbu i tried using your commands and it really helped !! I used rigidbody for gravity. What i don't get is why in the video that i used as tutorial the source code was the same as mine and its car was moving perfectly while mine is trembling and if i increese my speed it pierces the terrain. My project is not much just a cube with four cylinders attached under it moving on a larger cube and i followed all the steps in the video in the end i only had to change a bit the numbers in my source code to fix the movement a bit. This is my source code

 pragma strict
 public var forward_speed  : int = 5;
 public var backward_speed : int = 5;
 public var rotation_speed : int = 80; 
 function Start () {
 
 }
 
    
     static var speed : int = 5;
      
     function Update () {
     
     if (Input.GetKey (KeyCode.UpArrow)) transform.Translate (Vector3(1,-0.5,-0.55) * Time.deltaTime*forward_speed);
     if (Input.GetKey (KeyCode.DownArrow)) transform.Translate (Vector3(-1,-0.005,0.5) * Time.deltaTime*backward_speed);
     if (Input.GetKey (KeyCode.LeftArrow)) transform.Rotate  (0.0 , -rotation_speed * Time.deltaTime , 0.0 );
     if (Input.GetKey (KeyCode.RightArrow)) transform.Rotate (0.0 , rotation_speed * Time.deltaTime , 0.0 );
     if (Input.GetKey (KeyCode.Space) ) { rigidbody.AddTorque (Vector3.up* angularForce* Time.deltaTime);
                                           rigidbody.AddForce ( Vector3.up * upForce *Time.deltaTime); }
     
     }
      


[1]: http://www.youtube.com/watch?v=kE8nZL5FdQc

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

10 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

Related Questions

Slerp Problem?: Enemy in Constant Rotation! 1 Answer

using a custom rotation in "Instantiate" 4 Answers

Smooth rotation in 90° increments 0 Answers

How To Check If X Rotation Is Between Two Numbers?? 1 Answer

space flying system 3 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