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 egaito · Oct 19, 2012 at 07:52 PM · rigidbodyvelocitycartutorial

Question about rigidbody velocity

So I'm following the Car Tutorial available in the resources section of the site and am trying to do something similar, but much simpler, on my own. So far I'm just using a cube to represent a car. My problem comes when, like in the example code, I check the sign of the rigidbody velocity in the z axis against the sign of the vertical input. If it's the same it should add to the engine power, otherwise it should detract from it. My code looks like this:

     if(v == 0){
         currentEnginePower -= Time.deltaTime * 200;
     }
     else if(Mathf.Sign(v) == Mathf.Sign(relativeVelocity.z)){
         currentEnginePower += Time.deltaTime * 300;
     }
     else{
         currentEnginePower -= Time.deltaTime * 300;
     }
     
     if(currentEnginePower < 0){
         currentEnginePower = 0;
     }

This doesn't seem to work at all though. If the sign of the vertical axis (v) is positive, nothing changes. If I hold it at -1 the engine power jumps between 6 and a very small number, something like 1 * 10^-7. The engine power never has a different value than one of these two. It should be noted that the cube's position and rotation seems to constantly change in very small amounts. Any idea whats going on? Do I need to have wheels to make this work correctly? The reason why I don't have them is because I'm splitting the workload with a partner and I'm focused solely on the physics part of the project.

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

Answer by ShadowAngel · Oct 19, 2012 at 08:36 PM

i dont see anything thet modifis any rigdbody force. If u like more inside of how force works, just play a little with Rigidbody.AddForce() Here some exemple, its a JS script thet uses force to move a fighter:

 function Attack(Target : Transform)
 {
     var moveDirection : Vector3 = Vector3.zero;//intialize var for move direction.
     var targetRotation = Quaternion.LookRotation(Target.position - transform.position); // get a rotation we need to look at target.
     var Distance : float = Vector3.Distance (Target.position, this.transform.position); // get a distance from us to target
     var SpeedUp : float = 5/Distance; // Speed up multiplayer. Closer we are to a target, more force to move.
     var NextRotation : Quaternion = Quaternion.RotateTowards(transform.rotation, targetRotation, ThisAiActor.MaxSpeed/SpeedUp * 30 * Time.deltaTime);//Get a maximum rotation for this frame(to smoothly turn to our target)
     transform.rotation = NextRotation;//rotate our fighter for this frame
     
     
     moveDirection += Vector3.forward  * SpeedUp * ThisStats.EnginePower;//get force with what we gona push our fighter for this frame.
     moveDirection = transform.TransformDirection(moveDirection);//Transform forward direction from local to world.
     if (!ThisAiActor.DisableMovment)
         rigidbody.AddForce(moveDirection); //finaly push our fighter forward.(right and left movement we gona get from rotation becos we ALWAYS move forward)
 }
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

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

need tutorials for rigidbody.Addforce 1 Answer

how to set initial speed of vehicle 1 Answer

Car - WheelCollider - Why the side is getting up? 2 Answers

can't slow my car down 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