# Avoiding objects from appropriate side

Get help using Construct 2

### » Thu Dec 29, 2011 3:45 pm

I've made simple game prototype: http://tecbug.pl/pub/c2/avoidingballs/

As you can see, rockets are avoiding red balls.
But they always turn right. How can i make them to calculate where to turn to avoid balls faster (depending on ball centre and rocket movement vector)?

I don't kow if it's clear, so there's example:
If rocket moves right (angle 0) and if it collides with ball, construct should check:
if ball.y > rocket.y then rocket rotate right
if ball.y < rocket.y then rocket rotate left

Problem is that rockets have different angles...

There's CAP: http://tecbug.pl/pub/c2/avoidingballs.capx      tecbug2011-12-29 15:47:57
B
55
S
14
G
10
Posts: 287
Reputation: 7,677

### » Thu Dec 29, 2011 5:04 pm

there ya go
avoidBalls.capx
Last edited by Yann on Sun Sep 14, 2014 10:36 pm, edited 1 time in total.
B
69
S
22
G
14
Posts: 1,488
Reputation: 16,594

### » Thu Dec 29, 2011 6:55 pm

Very cool. Thnx Yann
B
44
S
24
G
13
Posts: 723
Reputation: 15,095

### » Fri Dec 30, 2011 12:29 pm

It compares only Y axis, and works only if rocket goes right. If it goes down, up, left (or at any other angles) this doesn't work.
Launch this (i used Your code) and wait o moment: http://tecbug.pl/pub/c2/avoidingballs2/
B
55
S
14
G
10
Posts: 287
Reputation: 7,677

### » Fri Dec 30, 2011 3:07 pm

Well it does what you asked
What you want is pathfinding. That's a bit more complex than the rule you described.
Well, pathfinding can be a bit hard on CPU maybe you can avoid using that by rephrasing the rule of your little ship. Basically what you want is not comparing Y, but comparing the relative position of the ball in object space. As if you rotate coordinates to align with the ship.
And it's really more complicated.
Though, I know how to do that. Hmmmm ok I'll do a capx.
avoidBalls.capx
There ya go

You will need to avoid placing balls to close together, the missiles have to have enough room to go betwen them (well they behave unexpectedely well if they get stuck they wiggle a bit and then turn around but the wiggling isn't really cool)Yann2011-12-30 15:09:29
Last edited by Yann on Sun Sep 14, 2014 10:34 pm, edited 1 time in total.
B
69
S
22
G
14
Posts: 1,488
Reputation: 16,594

### » Mon Jan 02, 2012 11:43 am

That's exactly what I needed. Thank You very much.
B
55
S
14
G
10
Posts: 287
Reputation: 7,677

### » Mon Jan 02, 2012 11:18 pm

Nice example - the parameter values as an example are very helpful.
B
9
S
2
G
5
Posts: 54
Reputation: 3,546