How do I rotate object to position then another?

Get help using Construct 2

Post » Tue Apr 18, 2017 5:28 pm

Hello Everyone,

So I have this code:
---------------------------------------------------------------------------------------
Event: System/every tick

Action: enemy / rotate 2 degrees toward(object1.x, object.y)
system / wait 2 seconds
enemy / rotate 2 degrees toward(object2.x, object2.y)
---------------------------------------------------------------------------------------
So when I run this code the enemy rotates to object1 but not object2.

How come?

Thank You.

Tri
B
24
S
4
Posts: 78
Reputation: 1,308

Post » Tue Apr 18, 2017 5:56 pm

The wait 2 seconds will trigger every tick as well, so after two seconds it will start trying to turn to object 2, but at the same time it's still trying every tick to turn to object 1 so it will remain facing object 1.

I'm guessing what you would like it to do is rotate to object 1, wait 2 seconds and then rotate to object 2?
If so, this should work:

Add an instance variable to the enemy called "target"; set it to 1.
Add a timer behaviour to the enemy.

Add this code to your event sheet:

Event: enemy| instance variable "target" = 1
Sub-event: enemy| NOT is within angle 2 of angle(enemy.X, enemy.Y, object1.X, object1.Y): Action: enemy| rotate 2 degrees towards (object1.X,object1.Y)
Sub-event: enemy| is within angle 2 of angle(enemy.X, enemy.Y, object1.X, object1.Y): Action: enemy | set timer "wait" to 2 seconds
Action: enemy | set instance variable "target" = 0

Event: Enemy| On timer "wait": set instance variable "target" = 2

Event: enemy| instance variable "target" = 2
Sub-event: enemy| NOT is within angle 2 of angle(enemy.X, enemy.Y, object2.X, object2.Y): Action: enemy| rotate 2 degrees towards (object2.X,object2.Y)

Hope that helps :)
B
19
S
8
G
3
Posts: 429
Reputation: 3,972

Post » Tue Apr 18, 2017 7:51 pm

Hello mekonbekon,

I got up to 2nd line of the event. How do I make it a NOT within angle.

Also when I set angle to '(enemy.X, enemy.Y, object1.X, object1.Y)' I get an error at first comma.

Not sure what I did wrong. Sorry.

Thanks.
B
24
S
4
Posts: 78
Reputation: 1,308

Post » Tue Apr 18, 2017 8:18 pm

Hi @Trimeister No worries :)

To make NOT you invert the condition: right click on the condition and select the "invert" option; it should add a big red cross to the condition. This is very useful for lots of conditions, so bear it in mind for the future.

For the angle you need to use the "angle" expression: select the "within angle" condition and in the angle field write "angle(enemy.X, enemy.Y, object1.X, object1.Y)". This provides you with the angle between two objects.

If that doesn't work give us a shout.
B
19
S
8
G
3
Posts: 429
Reputation: 3,972

Post » Tue Apr 18, 2017 11:14 pm

Hi mekonbekon,

Thank you sooo very much. It is working the way I wanted.

Best.
B
24
S
4
Posts: 78
Reputation: 1,308


Return to How do I....?

Who is online

Users browsing this forum: lordsas, mekonbekon and 61 guests