How do I rotate an object when condition met.

Get help using Construct 2

Post » Fri Mar 14, 2014 1:44 am

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.
B
19
S
7
G
7
Posts: 88
Reputation: 4,117

Post » Fri Mar 14, 2014 2:06 am

Can you show us your event sheet or post a capx?
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Fri Mar 14, 2014 2:10 am

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Fri Mar 14, 2014 2:23 am

nimos100 wrote: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.
B
19
S
7
G
7
Posts: 88
Reputation: 4,117

Post » Fri Mar 14, 2014 2:26 am

You have two actions for rotating objects.

Rotate Clockwise
Rotate Counter-clockwise

They are under the Angle section in the action menu.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Fri Mar 14, 2014 2:31 am

Image

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?
B
19
S
7
G
7
Posts: 88
Reputation: 4,117

Post » Fri Mar 14, 2014 2:32 am

nimos100 wrote: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.
B
19
S
7
G
7
Posts: 88
Reputation: 4,117

Post » Fri Mar 14, 2014 2:51 am

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Fri Mar 14, 2014 3:02 am

TheDoctor wrote:Image

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Fri Mar 14, 2014 3:05 am

nimos100 wrote: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?
B
19
S
7
G
7
Posts: 88
Reputation: 4,117

Next

Return to How do I....?

Who is online

Users browsing this forum: jorgmaquoi, marc254, tarek2 and 20 guests