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 /
avatar image
0
Question by Panhypersebastos · Oct 09, 2016 at 06:17 PM · positionobject movement

Transform.position values changing while object appears to be still?

Hi,

I have a gun object that is attached to an enemy character as a child of the hand object. There is an empty child object located at the end of the barrel that I am trying to use to spawn the bullets. For some reason the Y value of the transform.position for the spawning location is changing randomly, even though in the scene inspector it appears to be staying in the exact same position. I am getting the Y values outputted to the console with this line of code in a script attached to the empty object:

 Debug.Log(this.transform.position);


When I move the gun object so that it is a child of the parent prefab (rather than the hand) and just sticking out of the enemy's chest then this issue doesn't seem to be a problem and the values outputted to the console match the apparent position of the object. Does anyone have any guidance on how to go about solving this issue?

I have attached a screenshot from the editor showing how things are set up if that is any help.

alt text

vexingquestion.jpg (241.6 kB)
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 Bonfire-Boy · Oct 09, 2016 at 06:36 PM 0
Share

Is that the only place you're logging a Vector3?

It always puzzles me when people simply log a value. It makes it difficult to be sure what you're looking at in the console, unless you look at the call stack for each line.

So I would start by changing that line to (something along the lines of)

Debug.Log("$$anonymous$$uzzle position: "+transform.position);

avatar image Panhypersebastos · Oct 09, 2016 at 07:31 PM 0
Share

@Bonfire-Boy Yes, I am logging the vector3 only for the muzzle object, I am logging it twice, once from the script attached to the muzzle itself, and once from the script attached to the gun that is actually responsible for spawning the ammo. Both values are always matching.

avatar image Bonfire-Boy Panhypersebastos · Oct 09, 2016 at 07:36 PM 0
Share

That's a bit confusing. You say "yes" and then expand it into a "no"!

Since you're logging the same information in more than one place, it would make sense (for your own sake as well as to help show the issue to other people) if the logging each time told us which place in the code it is.

By the way, you should only use the "Your Answer" box when providing an answer to your original question. I have converted to a comment for you so that your reply to my question appears under my question.

avatar image Bonfire-Boy · Oct 09, 2016 at 07:41 PM 0
Share

As for your original question, I'm not sure that we have enough information. You probably need to show us the code.

One possibility is that the transform.position gets set back to the correct value before it renders. Another is that the difference between 2.1 and -1.5 is too small for you to notice at the scale you're working at. Are you just relying on the Debug.Log or are you also inspecting the transform's position in the inspector?

And what do you mean by "it is changing randomly"? The screenshot shows it only changing from one value to another values. Do you just mean that you can't explain why it changes? Or that all sorts of different numbers are appearing in the logged vector? Or what..?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Panhypersebastos · Oct 17, 2016 at 05:00 AM

I figured out what was wrong. For the benefit of anyone in the future who stumbles across this thread, the problem was that the character had rigidbodies on its limbs. Once the rigidbodies were removed I stopped getting this problem.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

Moving an object object x pos + speed?? 0 Answers

Set the position of a cloth 0 Answers

GUI button adjustments 2 Answers

Freeze rigidbody position without affecting rotation - please help! 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