# How do I make an object chase closer object

0 favourites
• 4 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
• lets say,

there are objects:

1. ob1

2. ob2

condition:

• there are many ob2s on the screen.
• only one ob1 is on the screen

Question:

1. how do i make ob1 chase an ob2 that is closer to itself?

2. how do i make ob1 rotate toward a closer ob2 relative to itself?

thanks!

• ## Try Construct 3

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

Construct 3 users don't see these ads
• You have a pick condition sprite > pick nearest. This picks the nearest sprite to a position.

So in one event you can combine the conditions:

Pick all ob1

pick nearest ob2 to x=ob1.x y=ob1.y

Now you have ob1 & the right ob2 picked, run actions to them as you like.

• First you need to pick the closest object using the pick nearest/furthest condition inside ob2

condition in ob2:

Pick nearest: X: ob1.X Y: ob1.Y

Then rotate and move ob1 using these actions. I have showed two different ways of doing this on both actions.

action: Rotate ob1 towards position (X: ob2.X Y: ob2.Y) or Set ob1 angle (angle(ob1.x,ob1.y,ob2.x,ob2.y))

action: Move at angle: (self.angle) or Move at angle: (angle(ob1.x,ob1.y,ob2.x,ob2.y))

• First you need to pick the closest object using the pick nearest/furthest condition inside ob2

condition in ob2:

Pick nearest: X: ob1.X Y: ob1.Y

Then rotate and move ob1 using these actions. I have showed two different ways of doing this on both actions.

action: Rotate ob1 towards position (X: ob2.X Y: ob2.Y) or Set ob1 angle (angle(ob1.x,ob1.y,ob2.x,ob2.y))

action: Move at angle: (self.angle) or Move at angle: (angle(ob1.x,ob1.y,ob2.x,ob2.y))

You have a pick condition sprite > pick nearest. This picks the nearest sprite to a position.

So in one event you can combine the conditions:

Pick all ob1

pick nearest ob2 to x=ob1.x y=ob1.y

Now you have ob1 & the right ob2 picked, run actions to them as you like.

thank you all!!!!!

• 4 posts