Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jul 29, 2018 at 01:48 AM by Icecoldless for the following reason:

问题已经得到解答,已经采纳了正确的解答

avatar image
0
Question by Icecoldless · Jul 28, 2018 at 04:49 PM · scripting problemvelocity

Why my object have velocity , but it can't move follow it's velocity?

    if (Input.GetMouseButtonUp(0))
         {
             aimMode = false;
             bulletRb.isKinematic = false;
             bulletRb.velocity = -tempPos*vc;
             print(bulletRb.velocity);
             bull = null;
         }

here ,I tried to follow this book to make a second game . I have a object named bullet , I get it's rigidbody : bulletRb, I set it's velocity when I press mouse button , I use a float value * a mouse position to point to the emitter position as the value of its speed ,but it doesn't work , it's motion like it's speed is 0,it just fall down because it's gravity ,but I print it's velocity , it have value . What's more strange is when I modify it's velocity from -tempPos*vc to tempPos*vc , It's back to normal.And it's the same result when I copy the source code from the book.

qq图片20180729004657.png (176.5 kB)
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

  • Sort: 
avatar image
0
Best Answer

Answer by Icecoldless · Jul 29, 2018 at 01:58 AM

The reason of problem is I haven't open isTigger switch in my Launching object . So I only can let it go out at the edge of the emitter, and if the velocity was the opposite, it would hit the object's collider and cause the velocity to go to zero in an instant.

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 Bunny83 · Jul 28, 2018 at 05:51 PM

To me it looks like your "bullet" (which is public) actually holds a reference to a prefab. From the little code preview on the right of your image we can see you actually have another gameobject reference called "bull" which most likely is an instance of your prefab "bullet". However we don't see where you may instantiate that prefab. Are you sure you get the Rigidbody from your bull object and not from bullet? If you get the rigidbody from the prefab it won't affect the instantiated / cloned object.


We don't see enough of your code to give a more precise answer. Note you should rename your "tempPos" variable as it doesn't represent a "position" but a direction. Without seeing the preview code in the image i would have assumed it actually represents a position and that most likely would be wrong. It's extremely misleading calling a variable "banana" when you store the current time in it. Many people seem to be lazy when they name their variables. As long as you know what you mean by that it's fine. However as soon as others should work on your code it becomes a problem as the purpose of a code snippet is not clear to us if the variable names are misleading.

Comment
Add comment · Show 1 · 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 Icecoldless · Jul 29, 2018 at 01:48 AM 0
Share

thank you answer my question,but I found the reason for the problem , I have instance of my prefab "bullet" in on$$anonymous$$ouseDown() method , I 'm sure I get the Rigidbody from my bull object and not form bullet , the reason is I haven't open isTigger switch in my Launching object . So I only can let it go out at the edge of the emitter, and if the velocity was the opposite, it would hit the object's collider and cause the velocity to go to zero in an instant.

 if (Input.Get$$anonymous$$ouseButtonUp(0))
         {
             aim$$anonymous$$ode = false;
             bulletRb.is$$anonymous$$inematic = false;
             bulletRb.velocity = -tempPos * vc;
             print(bulletRb.velocity);
         } 

this is how I test my velocity ,it only get velocity when I press mouse button , but in next frame , it hit emitter collider , so it's velocity will turn to zero in an instant.

Follow this Question

Answers Answers and Comments

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

Related Questions

What is wrong with this rigidbody? 2 Answers

Not able to find the problem in my movement code using velocity 2 Answers

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

How to use AddForce and Velocity together 1 Answer

calculate velocity of animated parent rigidbody from script inside child 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