#Conditions
1 messages · Page 1 of 1 (latest)
the next piece is that you have to be a bit more verbose
in Python, you can do something like -90 < rotation < 90, but that doesn't fly in C#
you have to be much more explicit
dang, alright
I've also just realized a subtle mistep on my part
you're looking for AND, which is &&
(that one's a bit easier to remember than or, haha)
yeah, i know that one
in this case, something like this:
if (transform.rotation.z > -90 && transform.rotation.z < 90)
you may want >= and <= respectively if you want it to still happen when it's exactly 90 or -90
alright
a trick that'll help you get where you need, if you don't already know it, is to put Debug.Log(something) in various places to figure out what is happening, what isn't happening, and what things are at those times
so something like this?
if(transform.parent.rotation.z <= -90 && transform.parent.rotation.z >= 90) {
GetComponent<SpriteRenderer>().flipX = true;
}```
possibly!
ima test it
that looks right-ish
if the flipX thing doesn't work, you might need to do transform.localScale
alrighty
mine looks like this for a 2d platformer that flips based on player input:
if (playerInputHorizontalDirection > 0)
{
transform.localScale = Vector3.one;
}
else if (playerInputHorizontalDirection < 0)
{
transform.localScale = new Vector3(-1, 1, 1);
}
so something like this would work?
void Update() {
if(transform.parent.rotation.z <= -90 && transform.parent.rotation.z >= 90) {
transform.localScale = new Vector3 (-1, 1, 1);
}
}```
hmm, it still seems to be doing nothing
it doesnt seem to be logging anything
wait, my bad, i put the debug log in the if statement
alright i put this in the update method
Debug.Log(transform, transform.parent);
and this is what it logged
Oh hmmm. Try logging transform.rotation
When in doubt log whatever she see where you're at
alright, i put this into the update method
Debug.Log(transform.rotation);
it logged this
i also had it log the transform.parent and it logged this
i dont know what else i can log to find out whats wrong :/
Ok so not parent
the weapon parent is what rotates
Right, but the rotation is only showing up when you do transform.rotation
alright
But maybe its rotating is separate of its parent
yeah, the rotation of the sprite doesnt change, thats why i was originally trying to flip the sprite from the parent instead of the sprite
so something like:
void Update() {
if(transform.rotation.z <= -90 && transform.rotation.z >= 90) {
GetComponentInChildren<SpriteRenderer>.flipX = true;
}
}```
That didnt work, and i think its because it isnt getting the rotation or something, because when i log something in the if statement it never logs anything no matter what the rotation is.
but i dont understand why
Oh I think it might be in radians not degrees
wait that actually makes sense, because the range for the angle jumps from 180 to -180 on the rotation