How do I rotate object to position then another?

0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • 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.

  • Hi mekonbekon,

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

    Best.

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