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 Nexgea · Dec 31, 2013 at 08:40 AM · rigidbodyvariablevelocity

In what var can I know the size of velocity

I want to know velocity of my object. I have rigidbody.velocity, but i cant save it to my var Speed I try int or float but nothing work. Can u help me?

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 Owen-Reynolds · Dec 31, 2013 at 03:30 PM 0
Share

velocity is a technical Unity term for when you let Unity's automatic physics system move the object, and makes it act "real." Your code sample below says you just snap to the mouse, so you don't have a velocity. Using "velocity" is confusing us.

You can remember how much you moved this frame. You'd have to save your old position, subtract and use magnitude. But that number will jump around a lot. A "smooth" mouse can easily move 10 pixels, 6 pixels, 0 pixels, -1 pixels (their hand jiggled,) 14 pixels ... . You can take the average speed, but that's trickier.

So, might help to know what you need it for.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by sath · Dec 31, 2013 at 08:56 AM

Maybe this can help you

http://answers.unity3d.com/questions/23992/current-speed-of-an-object.html

http://answers.unity3d.com/questions/323400/reading-dorce-on-rigidbody.html

http://answers.unity3d.com/questions/13256/get-current-speed-of-an-object.html

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 robertbu · Dec 31, 2013 at 08:54 AM

Velocity is a Vector3. So you can do:

 var myVelocity = rigidbody.velocity;

or

 var myVelocity : Vectgor3 = rigidbody.velocity;  

If you are just interested in the speed of the object, you can use the magnitude of the velocity:

 var speed : float = rigidbody.velocity.magnitude;
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 Nexgea · Dec 31, 2013 at 09:02 AM 0
Share

This is my code I am moving with the platform. I dont have component rigidbody in the inspector but this code have also error Cannot convert 'float' to 'UnityEngine.Vector3'

 private var ray : Ray;
 private var rayCastHit : RaycastHit;
 var Speed : float = rigidbody.velocity.magnitude;
 function Update ()
  {
      if(Input.Get$$anonymous$$ouseButton(0))
      {
           ray = Camera.main.ScreenPointToRay(Input.mousePosition);
           if(Physics.Raycast(ray, rayCastHit))
           {
           transform.position.x = rayCastHit.point.x;
           }
      }
      
      rigidbody.velocity = Speed;
      Debug.Log(Speed);
      
  }

thank u

avatar image robertbu · Dec 31, 2013 at 09:14 AM 0
Share

You need to save it as a Vector3. Either of the first two ways I outlined will work. Plus I don't know what you are trying to do with this code. If you initialize your velocity to rigidbody.velocity, you should do it in Awake() or Start(), but it makes no sense to save the velocity or the speed before any code has run that changes the velocity since velocity will be Vector3.zero. So you can do:

 var myVelocity = Vector3(0,0,4);

and then just set the values in the Inspector if you like something different.

Then line 15 becomes:

 rigidobdy.velocity = myVelocity;
avatar image
0

Answer by TheShadowblast123 · Dec 31, 2013 at 09:16 AM

javascript right?

rigidbody.velocity is a Vector3 that as you know Stores the velocity

because of that you must put it in a Vector3. Here's a cool way I found out how to do it:

  1. private var holdMyVelocity : Vector3;

  2. holdMyVelocity = rigidbody.velocity;

"but I can't see it" go to the top corner of the inspector where there's a lock. just right of it there's a tiny drop down. click it and go to Debug. Now you can see loads of information you normally wouldn't be able to. The bigest benefit from this is that if you ever need to see your velocity again... you could always reactivate debug mode.TheInspector


inspectoroptions-0.jpg (13.8 kB)
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

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

Related Questions

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

Calculating speed of rigidbody? 1 Answer

rigidbody.velocity.normalized application 1 Answer

Velocity for movement 0 Answers

Rotate Rigidbody Towards Velocity? [3d] 0 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