• 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 Dec 16, 2020 at 12:09 PM by imbarawr for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by imbarawr · Dec 16, 2020 at 06:08 PM · rotationbug-perhaps

Gameobject position not the same as it is presented

I have ran into an issue when my character is facing straight downwards in a 2D game.

As seen below this is how he should appear, weapon in his right hand and bullets originating from firepoint, marked with red star (a sprite rendered to make it more clear) alt text

When aiming straight down Z rotation changes to 0 and X rotation to -180 making the character mirrored. I tried fixing this issue with a script that simply flips the character correctly when its Z rotation is a certain value and it works, the character no longer looks mirrored.

 if (zAngle == 180f) 
 {
 transform.Rotate(180,0,180);
 }

However, the red star on the tip of the weapon is a sprite rendered on a child gameobject to the player called firepoint which is used as a location to instantiate bullets. When I shoot while facing down, even tho the weapon is placed in the characters right arm and the red star (the firepoint), the bullets originates from where the firepoint would be if the weapon was in the characters left arm. Like this: alt text

I have an output of the position.x and position.y of the firepoint gameobject and it changes more than it should when looking straight down, making it not being in the same location as the spriterenderer attached to said gameobject. Graphic wise it is correct but the position of the gameobject is not where it is presented graphicly. Any ideas or suggestions is much appreciated!

4.png (173.8 kB)
3.png (216.1 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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by imbarawr · Dec 16, 2020 at 12:06 PM

Solved it, had a eureka moment and figured it out.

The script that flipped the character correctly was after the script that checked if the fire button was pressed, resulting in the firing happening before the flipping of the character and therefore having the wrong position where bullets originate from.

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

189 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

Related Questions

NavMesh Agents: They won't stop when you want them X units away from the target and 2 other questions... 0 Answers

Freeze Rotation constraints doesn't work. 2 Answers

Camera with X rotation inside 270 1 Answer

Flip over an object (smooth transition) 3 Answers

Canvas wired rotation bug 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges