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 /
  • Help Room /
avatar image
0
Question by On-Stand-By · Nov 26, 2017 at 12:37 PM · unity 5vector

Vector value is (0.0, 0.0) when using variable

Hi,

It's the second time it happens to my game. When I use a Vector2(hSpeed,0) (or Vector3), it always return with 0 value. But when I give it a brute value it works fine. I use it like that :

 rb2d.AddForce(new Vector3(hSpeed, 0, 0));

But the strange thing is that I use it the same way with transform.translate();

 transform.Translate(new Vector3(hSpeed, 0, 0));

And it works fine ! But in a Debug.Log(); it displays (0.0, 0.0).

10 hours works on my game and you can just move, jump, if you jump on a monster it Destroy it and makes you bounces. 2 hours to do that, 8 hours to try to debug stupid Unity Behaviour like this... It's really pissing me off to always find a workaround with ducktape.

Can someone explain why it does this ?

Edit : I use Unity 5.6.3p1, which is the last version available.

Comment
Add comment · Show 5
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 shakecaine · Nov 27, 2017 at 12:12 AM 0
Share

What is the thing you debug exactly and where?(show the code and explain what is the expected value and why in your opinion it should be different) It is most likely your misunderstanding of what is the state of the object in the situation you are debugging it and logging the result which is (0.0, 0.0) at that moment.

avatar image On-Stand-By · Nov 27, 2017 at 10:47 AM 0
Share

Yes sorry I should be more precise. The debug and hspeed are :

 hspeed = Input.GetAxisRaw("Horizontal") * Time.deltaTime;
 Debug.Log(new Vector3(hspeed, 0, 0));

And it returns (0.0, 0.0, 0.0) when hSpeed is around 0.016f But it seems to returns correct value when used in Transform.Translate(new Vector3(hSpeed, 0, 0)); because it moves my character, but not with Rigidbody2D.AddForce(); And like I said when I do something like Rigidbody2D.AddForce(new Vector3(0.016f, 0, 0)); it works fine. And using Vector2 or Vector gave the same result.

After deeper research, I found that a lot of people are facing this issue from serverals Unity versions. Oldest post on it date from $$anonymous$$arch of this year.

avatar image Hellium On-Stand-By · Nov 27, 2017 at 10:54 AM 0
Share

When outputting a vector, the values are rounded, explaining why you have (0,0,0).

I think the reason why your object does not move using AddForce, is that the force you apply is not big enough (compared to the mass of the rigidbody). Try to increase the applied force with a factor you can change in the inspector.

avatar image On-Stand-By Hellium · Nov 27, 2017 at 11:04 AM 0
Share

I don't think so, when I display hSpeed it's not rounded at all, maybe it's like that when outputing from a class contructor but I find the idea a bit stupid as it can leads you to search elsewhere for the issue, and it's not precised in Unity documentation. But if you're right, is there a way to force it to display compete value ? By the way, I'll try your solution this evening and give you a feedback about.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

194 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 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

RayCast not working as expected, help! 1 Answer

Is there a Avatar Mask for 2D skeletal Animation? 0 Answers

Collider visibility in Scene View 0 Answers

How to I script a "aoe" click to change multiple sprites in one click,How do I make a 0 Answers

UCE0001: ';' expected. Insert a semicolon at the end. 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