Bouncing Enemies That Change Directions

For questions about using Classic.

Post » Tue May 10, 2011 1:28 am

I can't get this to work. If I try to rotate they get stuck/bounce off at random angles from the things they bounce off, if I try setangle they get stuck on the second bounce after working correctly the first time. I just want enemies that bounce back and forth and change direction every time they bounce.

dropbox link to .cap file here:

http://dl.dropbox.com/u/22863144/sailboatgame.cap
B
1
G
1
Posts: 9
Reputation: 443

Post » Wed May 11, 2011 3:42 am

I did update the cap but noticed yours was saved in an earlier version so here's some code instead (only replace the collision event, I only added the private variable test so you could recognise where I mean)....

Replace...

On collision between enemy1 and terrain
enemy1: Value 'Right' Equal to 1

On collision between enemy1 and terrain
enemy1: Value 'Left' Equal to 1

WITH

enemy1: overlaps Terrain : offset(2,0)
enemy1: Value 'Right' Equal to 1

enemy1: overlaps Terrain : offset(-2,0)
enemy1: Value 'Left' Equal to 1
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Thu May 12, 2011 6:53 pm

The offset idea is good but I'm still not sure how to get the enemy to bounce correctly. Setting angles doesn't seem to work, the simple bounce action doesn't work (although one of the enemies bounces in that case ???), and doing a rotation doesn't really work either.
B
1
G
1
Posts: 9
Reputation: 443

Post » Thu May 12, 2011 7:42 pm

Why not give the enemy ships the Ball behavior instead of the 8-direction?
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Sun May 15, 2011 9:46 pm

That's a good idea. I tried it and it works OK but they bounce around in different directions. Is there a good way to constrain them to left/right or up/down (ie 90 degree angles) only?
B
1
G
1
Posts: 9
Reputation: 443

Post » Mon May 16, 2011 8:34 am

In that case you could use the bullet behavior with a event "on collision with terrain" rotate 180 degrees CW.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Wed May 18, 2011 8:12 pm

The bullet thing worked great. Thanks!
B
1
G
1
Posts: 9
Reputation: 443


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests