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 Matthew0123 · Jan 20, 2013 at 06:23 PM · javascriptmovementrigidbodyvelocity

Movement using rigidbody.velocity to apply a constant force until stop

I am trying to make a constant force of a ship sailing using velocity. I got the movement down, but I am trying to make it only go FORWARD. As in the way the ship is pointing. Not where ever the user is pointing. I got no idea how to do this and I've tried several ways to see if I can.

 #pragma strict
 
 function Start () {
 
 }
 var move : GameObject;
 
 private var speed: float;
 private var turnSpeed: float;
 private var interaction: String; //interaction type
 private var ship: String;
 function Update () {
     interaction = GameObject.Find("First Person Controller").GetComponent(Interactions).interaction; //Check interaction
     speed = 100;
     turnSpeed = 10;
     ship = GameObject.Find("First Person Controller").GetComponent(Interactions).Helm;
     move = GameObject.Find(ship);
         if (Input.GetKey(KeyCode.W) && interaction == "Helm") {
             move.rigidbody.velocity = transform.TransformDirection(Vector3.forward * speed); // Add a forward motion onto it.
         }
 
 }
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
3
Best Answer

Answer by sparkzbarca · Jan 20, 2013 at 06:38 PM

velocity is an actual speed. It SOUNDS LIKE you want to increase or decrease speed.

AddForce does thats

velocity doesnt increase or decrease. It sets.

If i had an object traveling 300 meters per second and i set velocity = 0 it would stop INSTANTLY no slowing down. If i then set it to 500 meters per second it would Instantly begin traveling that fast without having gone any slower in between.

to increase speed

rigidbody.AddForce(direction * speed)

OR IN YOUR CASE

rididbody.AddForce(tranform.forward * meters per second)

now you'll need to add a limiting check to ensure speed doesnt exceed a certain limit.

velocity gives you the meters per second it is traveling in each of the 3 axis's

since your always adding force in the forward axis you could do a simple speed check via

MaxSpeed = transform.forward * MaxSpeedInMetersPerSecond;

if rigidbody.velocity > MaxSpeed rigidbody.velocity = MaxSpeed;

NOW REMEMBER ITS METERS PER SECOND if you want your physics sim to work out right and lets say you want 60 miles per hour as your speed, your going to have to convert, unity speed is always meters per second. You keep that in mind for the purposes of keeping stuff relative. You don't want a boat going 60 meters per second and a human 40 because first off thats a stupid fast boat and secondly that is an even more stupid fast human. If you don't give things realistic speeds then the physics that comes out of those calculations wont be realistic. Collisions might look crazy because your boat is traveling crazy fast. You can have a 60 meters per second object but it will behave as such in calculations. Thats why you can't just say oh its 60 whatever per whatever, because the force applied in a collision for example is meters per second.

mark as answerd and have a nice day :)

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 Matthew0123 · Jan 20, 2013 at 07:00 PM 0
Share

Thanks, I'll keep this in $$anonymous$$d and thanks for a great explanation! Yes I knew velocity was a constant speed, but force sounds better. Thanks again.

avatar image Matthew0123 · Jan 20, 2013 at 07:17 PM 1
Share

Also one thing... It goes every direction, BUT forward and backwards. If Ii look to the side it will go to the side...

avatar image DSebJ · Dec 23, 2013 at 12:02 PM 0
Share

Thanks so much, perfect explanation.

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

11 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

Related Questions

rigidbody It's going up and bounces when is moving 1 Answer

Rigidbody - Applying One-Time Force? Not Constant Force 2 Answers

How to set velocity of Rigidbody without changing gravity? 1 Answer

Weird Movement 1 Answer

help fix my script 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