How do I make an object chase closer object

Get help using Construct 2

Post » Thu May 19, 2016 2:09 pm

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!
B
8
Posts: 3
Reputation: 563

Post » Thu May 19, 2016 2:52 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu May 19, 2016 3:02 pm

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))
B
8
S
2
Posts: 24
Reputation: 536

Post » Thu May 19, 2016 5:50 pm

BunnehBoy wrote: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))

99Instances2Go wrote: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!!!!! :D :D :D :D :D :D :D
B
8
Posts: 3
Reputation: 563


Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, Yahoo [Bot] and 51 guests