#Gun Flipping Issue
1 messages · Page 1 of 1 (latest)
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)
Wait. Why did just flipping the sprite not work again?
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
because the children objects wouldn't flip
let me try
okay i've tried everything regarding this
it did not work
i think Quaternion.Euler is the better option
but as long as a way works, I'd use it
okay, im not sure im putting it in the correct way, but doing this fixes the rotation or the values going below 1
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
this works for you? if this works it's probably fine
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;
it is
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
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
actually, i'll give you the updated video, and a video with no other variables such as flippedEulerZ or multiplying the rotation with 100 to get out of 0.01 values
maybe that might help
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
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
check the inspector in the video, the issue is when i include the if else statement, the transform.rotation.z goes below 1
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
and i am not trying to make it super sensitive or smaller rotation
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
ah, you're using quaternion values instead of eulerAngle values for Quaternion.Euler input
im not sure myself, but i do think i do what you said, heres what i do incase im wrong
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset);
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