How do I rotate an object when condition met.

1 favourites
From the Asset Store
Simple resize and rotate events for any sprite, quick and easy event sheet that you can use for your own projects.
  • I am trying to rotate my player 1 degree counterclockwise 90 times with a fraction of a second inbetween rotations when a condition is met. I want the user to see the player on the screen actually rotate not just jump to 90 degrees.

    I've read the manual about loops, I just can't get it to loop 90 times inside when a condition is met. Outside of a condition, no problem. I can't find a tutorial either.

    This is becoming a real headache.

  • Can you show us your event sheet or post a capx?

  • Since C2 runs 60 ticks every second. You have to divide the amount of degree you want to rotate every second with that. You don't need a loop you can just do it every tick.

    Action:

    Rotate <Something> clockwise = 90 / 60

    Will rotate it 90 degree every 1 second.

    Rotate <Something> clockwise = 180 / 60

    Will rotate it 180 degree every 1 second etc.

  • Since C2 runs 60 ticks every second. You have to divide the amount of degree you want to rotate every second with that. You don't need a loop you can just do it every tick.

    Action:

    Rotate <Something> clockwise = 90 / 60

    Will rotate it 90 degree every 1 second.

    Rotate <Something> clockwise = 180 / 60

    Will rotate it 180 degree every 1 second etc.

    I fail to see how you implement on the event sheet....I do not see a corresponding action for that.

  • You have two actions for rotating objects.

    Rotate Clockwise

    Rotate Counter-clockwise

    They are under the Angle section in the action menu.

  • This works while the condition (Mouse On any Click) is Toggled to Disabled.

    Once I Toggle the condition to Enabled (not crossed through) it only moves 1 time not 90.

    What am I doing wrong here?

  • You have two actions for rotating objects.

    Rotate Clockwise

    Rotate Counter-clockwise

    They are under the Angle section in the action menu.

    And neither one of them has a number of iterations. That code will only move once. Only move a fraction of the full 90 degrees.

  • It will use the ticks iteration of 60 automatically.

    What you can do is add a Boolean variable to the objects that you need to rotate, called "Rotating"

    In the event that rotate.

    Object.Rotating true

    Object.rotate clockwise = 90 / 60

    And then you set it to false again when its done rotating.

  • This works while the condition (Mouse On any Click) is Toggled to Disabled.

    Once I Toggle the condition to Enabled (not crossed through) it only moves 1 time not 90.

    What am I doing wrong here?

    The reason it doesn't work is because it not really a valid way of using the events. You repeat it 90 times every tick. But afterwards you have added a Wait 0.3 so even though it runs 90 times, it gets stuck at the 0.3, so you could change it to repeat 1 time, and it would be the same. The amount of times you repeat it are way faster than 0.3 second of wait time.

    The way you want to do it in your code is not based on a 1 second interval, but just on a random amount of time. The reason mine work is because its based on C2 running 60 ticks a second, Which means that it will run through your event sheet 60 times in a second.

    So dividing 90 degree with the 60 ticks, will tell C2 to rotate the object 1.5 degree every tick. And therefore after 1 second it will be 90 degree.

    In you example, try to change the repeat to an

    "Every tick"

    And remove the wait and move the rotate up, and type 90/60 as how much it should rotate, it will make it rotate 90 degree every 1 sec.

    "Every tick"

    Rotate object 90/60 degree.

  • It will use the ticks iteration of 60 automatically.

    What you can do is add a Boolean variable to the objects that you need to rotate, called "Rotating"

    In the event that rotate.

    Object.Rotating true

    Object.rotate clockwise = 90 / 60

    And then you set it to false again when its done rotating.

    Oh boy, do you have an example of that? What you say works fine outside of a condition being met, but not inside. I simple want to see one loop that works inside a condition being met.

    For example, see my code picture above? Can you make that work by making a simple change?

  • And remove the wait and move the rotate up, and type 90/60 as how much it should rotate, it will make it rotate 90 degree every 1 sec.

    "Every tick"

    Rotate object 90/60 degree.

    That's wonderful if I want to do something "Every Tick". I don't want to do it every tick, I want to do it only 90 times and USING A LOOP INSIDE OF A CONDITION BEING MET. That is the topic of my entire post. I want to know how to structure it.

    I am basically asking everyone "Can a loop be executed inside of a condition being met?"

    I don't want to use a behavior, I don't want to call a function (tried both of those still couldn't). I simply want to know how to structure a loop that fires off only once a condition is met.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here is an example, that will rotate it 90 degree every 1 second, when you click the object.

    https://dl.dropboxusercontent.com/u/109921357/Rotate_test.capx

  • [quote:1301ywbs]That's wonderful if I want to do something "Every Tick". I don't want to do it every tick, I want to do it only 90 times and USING A LOOP INSIDE OF A CONDITION BEING MET. That is the topic of my entire post. I want to know how to structure it.

    I am basically asking everyone "Can a loop be executed inside of a condition being met?"

    I don't want to use a behavior, I don't want to call a function (tried both of those still couldn't). I simply want to know how to structure a loop that fires off only once a condition is met.

    Yeah you can run a loop if conditions are made, but what you are trying to do, is not possible the way you want to do it. Because a loop is not based on the time scale you are aiming for. To make what you are trying to do work, you would need to know how fast the loop is executed, as I understand you. Which would be near impossible to figure out as I see it.

  • Uhm, that works, but it doesn't answer my question...unless you are trying to say "NO, you can not use a loop inside of a condition being met."

    Thanks though for giving me a way to do it, but I am really trying to understand using loops like REPEAT. Like I said, I can get them to work PERFECTLY outside of a condition being met, but once I put it inside a condition being met it does not work.

    Can anyone answer my question?????

  • Yeah you can run a loop if conditions are made, but what you are trying to do, is not possible the way you want to do it. Because a loop is not based on the time scale you are aiming for. To make what you are trying to do work, you would need to know how fast the loop is executed, as I understand you. Which would be near impossible to figure out as I see it.

    According to the manual,

    Wait

    Wait a number of seconds before continuing on to the next action or sub-events.

    So, my thinking is that when it reaches my "Wait" it will "Wait a number of seconds before continuing on to the next action or sub-events." This is what it does outside of a condition, but inside not so.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)