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 mohd-ma · May 05, 2014 at 12:23 PM · javascriptobjectspeed

how i know my object speed ?

hi , please how i can know the speed of my object i shooted it . because i want to execute function when this object stop and it speed = 0 . I,m still new in unity :( function Shoot(){

 var ball= Instantiate(Ball, transform.Find("me").transform.position, Quaternion.identity);
 ball.rigidbody.AddRelativeForce(transform.forward * Force );
 
 ball-=1;
 }
 
Comment
Add comment · Show 4
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 Wolfram · May 05, 2014 at 04:09 PM 0
Share

The statement "ball-=1;" doesn't make sense. What do you expect it to do?

avatar image mohd-ma · May 05, 2014 at 04:23 PM 0
Share

Ball-=1 to decrease the balls number after i shoot

avatar image Wolfram · May 05, 2014 at 04:26 PM 0
Share

But "ball" is your instantiated object, and "Ball" is the object you instantiated from. None of those are integers. Do you have a differently named variable that tracks the number of balls? It must be named differently.

avatar image mohd-ma · May 05, 2014 at 04:32 PM 0
Share

Hhhh yes i changed the variable name when i copied my code here. Thanks :)

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by fafase · May 05, 2014 at 12:25 PM

  print(rigidbody.velocity.magnitude+"unit/s");
Comment
Add comment · Show 6 · 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 mohd-ma · May 05, 2014 at 12:33 PM 1
Share
     var ball= Instantiate(Ball, transform.Find("me").transform.position, Quaternion.identity);
     ball.rigidbody.AddRelativeForce(transform.forward * Force );
      print(rigidbody.velocity.magnitude+"unit/s");
     
     ball-=1;
     }
 

it gets me 0 unit / s !! please tell me how i write the code exactly . thanks

avatar image fafase · May 05, 2014 at 03:33 PM 0
Share

You need to have the print in the Update or any kind of repeating method. I would guess this bit of code is only code once so at this time the velocity is zero but next frame it will be positive.

avatar image Wolfram · May 05, 2014 at 04:38 PM 0
Share

You'll need to use ball.rigidbody.velocity.magnitude, not rigidbody.velocity.magnitude. The latter refers to the rigidbody of THIS gameObject, which might not even exist. Also, when putting this in Update, your variable "ball" must be globally visible, ins$$anonymous$$d of being declared within Shoot().

avatar image mohd-ma · May 05, 2014 at 04:42 PM 0
Share

Thanks a lot dear, i.ll try

avatar image mohd-ma · May 05, 2014 at 07:44 PM 0
Share

I make like this but no responding :( what,s the wrong please ?

 var darba= Instantiate(Ball, transform.Find("myhand").transform.position, Quaternion.identity);
 darba.rigidbody.AddRelativeForce(transform.forward * qowwatDaf3 );
 print(darba.rigidbody.velocity.magnitude+"unit/s");
 BallNum-=1;
 }
Show more comments

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

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

Related Questions

Current speed of an object? 5 Answers

Storing and using weapons and objects 0 Answers

How can I implement a SimpleMove max speed? 1 Answer

Disable GameObject Only Father Not Children 2 Answers

Run through hastable of objects 1 Answer


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