#Gun Flipping Issue

1 messages · Page 1 of 1 (latest)

gentle roost
#

the video i provided is what happens if i multiply the transformation.z with 100 in the transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.z); part of the if else statement

#

if i do not multiple it, then it is also static (seems asif it can only face right or left without any rotation, however a closer look, and you can see that is very slightly rotating, it just cannot be easily observed)

strange quail
#

Wait. Why did just flipping the sprite not work again?

copper estuary
#

the rotation likely has to be adusted as well, something like
flippedRotationEuler = 360f - originalRotationEuler;

#

possibly related
#old_unity message

#

and if you read through this, seems like a similar/same problem
#old_unity message

gentle roost
strange quail
#

Oh true.

#

Can’t you do scale.y = -1?

gentle roost
#

let me try

gentle roost
#

it did not work

#

i think Quaternion.Euler is the better option

#

but as long as a way works, I'd use it

gentle roost
#
float flippedEulerZ = 360f - rotZ;

        if(Mathf.Abs(rotZ) >= FlipThreshold){
            transform.rotation = Quaternion.Euler(transform.rotation.x, 180, flippedEulerZ);
        }
        else{
            transform.rotation = Quaternion.Euler(transform.rotation.x, 0, flippedEulerZ);
        }
#

this is what im doing rn

copper estuary
#

but i thought that looking at your video above, since the gun rotates into the opposite direction when flipped, this part at least will be important
float flippedEulerZ = 360f - rotZ;

gentle roost
#

its the only thing

#

that has somewhat bought the rotation to near fixing

#

the left flipping is still not fixed though

#

its just not as glitchy as the video, im trying to fix the flipping rn

copper estuary
#

do you have an updated video?

#

right now if you scale flip but also rotate around y 180 degree, not sure how that behaves, usually I only see it being flipped without the y rotation

#

in 2d, generally every euler angle for sprites aside for z is aways 0

#

from the games I've seen

#

I guess a 180 degree y rotation is a different way to"flip" a sprite

gentle roost
#

maybe that might help

gentle roost
#

the code for this case is

if(Mathf.Abs(rotZ) >= FlipThreshold){
            transform.rotation = Quaternion.Euler(transform.rotation.x, 180, transform.rotation.z);
        }
        else{
            transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.z);
        }
#

the very first video i gave

#

was just multiplying the transform.rotation.z with 100

#

inside the if else

copper estuary
#

I don't really get this video,
like multiplying with 100 should give a super sensitive rotation
in the video the gun barely moves
and if that's the goal, I'd just flip it or do the 180 y rotation like you have

otherwise i get the angle from the forward direction and adjust it if you really want a smaller rotation

Vector2 gunToMouse = mouseWorldSpacePos - gun.transform.position;
Vector2 lookDir = isGunFacingRight ? Vector2.right : Vector2.left;
float angleFromLookDir = Vector2.SignedAngle(gunToMouse, lookDir);

and then you can adjust the angle (multiply it) and try to convert it back,
which might mean flipping, or adding 90 degree (depending on what the neutral z rotation of your gun is, like if the neutral rotation (z = 0) of the unfipped gun is already to the right then this shouldnt be necessary

gentle roost
#

to values like 0.089

#

and etc

#

its fine when there is no if else that has, and a value like 0.089 is 89

gentle roost
#

its just that it isn't normally rotating

#

and when it is, its too much

#

i will try out the other stuff you said though

copper estuary
#

ah, you're using quaternion values instead of eulerAngle values for Quaternion.Euler input

gentle roost
copper estuary
#

that looks better
seeing what your default rotation is (meaning gun looks to the right), it might be worth to do something like this
#1060227103473291314 message

#

and you could try to use angleFromLookDir for the z eulerAngle
transform.eulerAngles = new Vector3(0f, 0f, angleFromLookDir );

#

btw, this is the same as transform.rotation = Quaternion.Euler
in functionality, it's just that you can directly assign the eulerAngles too if you want