How to sum quarters of 90º through booleans once every time.

Hello Procoders!

I hope someone can help me, I’m trying to sum quarters of 90ª through booleans while my character is doing a 360º rotation with sprites!

I have 2 problems, one of them is that if I create an int to control the rotation every frame that a bool is true the int increase +=90 but it’s completely dyscontrol because it sums every frame.

The other problem is that I can control it by establishing a lot of different booleans like spin1, spin2… and when spin4 is true then we are going to post a second round and like this… to reach spin16 for example that it means the character has rotated 1440º… but it’s a little crazy to do this in the code and it’s not working properly due the sprites are gameobjects where they are activated or not depending on the frame for each 90º of the rotation so sometimes it no detect properly the position exact.

Any idea about how can I sum quarters of 90º through sprites?

Thanks in advance.

Switch the booleans for integers, and increment by 90 * count. If, for example, you were thinking to spin 2 quarters, instead of that being the result of two bools, make it the result of an integer being 2. In that code where you’d set one of many bools, set the integer to the logically related value instead.

Hi JVene! thanks for answering.

I’ve tried to apply directly the integers and then do the formula, but I still have the same problem since I use a conditional to know exactly in what position is the player to follow properly the next rotation in case that the user only want to rotate for example 90º, so when I use count +=1 during that moment still summing a lot because is in the update void.

This is how I established the code to calculate the rotation:

if (anim360.GetCurrentAnimatorStateInfo (0).IsName (“1nose”)) {

            oneNose = true;
            twoBackCam = false;
            treeTail = false;
            fourFrontCam = false;

            //player.count += 1; --> I want to sum just +1 and not a lot of +1.
        
        } 

        if (anim360.GetCurrentAnimatorStateInfo (0).IsName ("2backcam")) {

            oneNose = false;
            twoBackCam = true;
            treeTail = false;
            fourFrontCam = false;

            //player.count += 1;
        }

        if (anim360. +2more...

While the gameobject is available at least near a second during the animation of the sprites making the rotation of the character, the count sum a lot of times so I can not detect properly the count.

I want to sum just one any time the character do the animation, and when it is finished I will calculate with the formula. But we need to sum just +1 each time.

Hi JVene, thank you again for answering.


I’m a self-student, so probably I’m worse than a new student who use a school to improve his skills because my only “teachers” are videos from the internet and forums, in fact, you are the person with more knowledge and experience in this sector that I’ve met, also, I can only work on my project in my spare time because I have another job to be able to live… I started from 0 in art and dev last September and my knowledge of C-sharp is very basic, (I’m working in this game: https://twitter.com/Twintipgame/status/1013767442454188034 , it’s not a big thing… but is my first game and is a completely a solo indie game…), here you can see what I have done approx and where I’m applying the rotation, but the point is how to calculate by quarters the exact rotation and with your argument from the last answer gave me new ideas about how to focus the problem, and finally after a lot of hours working and thinking about it I found a solution that seems to fit with my level!


I tried to simplify the process, and I saw (thankful to your concept about the “wrapping”) that I needed to establish a condition when the count sum 1 to avoid to increase more the count in the update void, so I did a method where I’ve created two strings, one named oldAnim started in null, and the other named currentAnim, where I check in every moment which Anim is running, like currentAnim = “1nose” or currentAnim = “twobackcam… threetail…” then I put a conditional saying if (oldAnim != currentAnim) then count++ and after that I did my “wrap” saying oldAnim=currentAnim, so the condition is not more true, and the sum is only just +1, and doing this it seems it works :slight_smile:


I only have one thing more that I’m not understanding in all, that the first time that I do the first quarter my count sum 2 times, and after the first time when I restart the count = 0 when the character stops to spin, it works properly summing 1 by 1. I think this has to do something about the first time the oldAnim = null, but I can not understand yet in all. My first solution of that is to establish the count the first time ever at -1, and then it works all fine.


Thank you again for all your time, you have helped me a lot :slight_smile:

Marc.