0 Favourites

How do I test if moving left or right.

  • I am attempting to make A.I. for the enemies in my game. The enemies have line of sight and platform behaviours. I need to know if there is a way to test if they are moving left or right. I thought that there would be a test for X vector in platform conditions but I didn't see it. Please help because I can't really progress with their A.I. until I figure this out.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • If you want an enemy to follow you, give the enemy an instance variable like var_walking. Then in your events you can set up something like this:

    Set the variable:

    if enemy has line of sight to player

    if enemy.x < player.x+1 -> set var_walking 0

    if enemy.x > player.x -> set var_walking 1

    Make the event happen:

    if var_walking = 0 -> simulate control left

    if var_walking = 1 -> simulate control right

    You can also just do walking with the same variable and events if you don't want the enemy to follow the player. Something like this should work set up when the enemy doesn't have line of sight:

    On collision with obstacle -> set enemy var_walking to 1-enemy.var_walking

    I hope that makes sense.

  • I am attempting to make A.I. for the enemies in my game. The enemies have line of sight and platform behaviours. I need to know if there is a way to test if they are moving left or right. I thought that there would be a test for X vector in platform conditions but I didn't see it. Please help because I can't really progress with their A.I. until I figure this out.

    The expression 'Sprite.Platform.VectorX' gives you what you look for.

    To use it in a condition.

    Pick the Enemy (anyhow anyway)

    System > Compare two values ... first = Enemy.Platform.VectorX ...... comparisation = < ...... second = 0

    .............actions run if it goes left

    Else

    System > Compare two values ... first = Enemy.Platform.VectorX ...... comparisation = > ....... second = 0

    .............actions run if it goes right

    Else

    .............actions run if it goes not right and not left

  • Thanks 99instances2go.

    That's exactly what I needed, just skipped my mind that I could do that.

  • After trying some stuff I've hit a problem. I can successfully test if a single enemy is walking and animate accordingly but with multiple enemies it doesn't work.

    The enemies are made of a base 'body' where a hair, top and pants sprite are pinned (multiple sprites for different colours and styles of enemies.) The body is controlled by the platform behaviour while the clothes and hair are pinned to the body. I can't just test the x velocity of the body for clothes and hair as it just takes it from the first spawned enemy. (e.g. If the first enemy is at a wall not moving another enemy which is moving will play a still animation for its clothes and hair.)

    Is there a way to link the speed of one sprites to its own components, or is there an easier way to go about this. (btw the body and its clothes and hair are in a container together.)

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