Enemy Tank AI

For questions about using Classic.

Post » Thu Feb 25, 2010 8:45 pm

[quote="Neo1000":3nhdawbs]Great, I fail to do the timer settings, because all the tanks rotate at the same time. I know it has something to do with the "Turn" Private variable. The link to the cap is still the same.[/quote:3nhdawbs]

Your event is picking all of the Tank instances. If you want each on it's own timer, then you should give each it's own timer.

Make a "myTimer" private variable. On start of layout, do "For Each tank -> Set 'myTimer' to random(however long)."

Then in the main movement loop do "For Each tank -> subract from 'myTimer' whatever amount." Then when the tank's timer is less or equal to zero, give the turn command and generate a new random amount for their timer.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Feb 26, 2010 6:16 pm

Hmm, but the Turn Event is used to make the tanks turn around. They only have the bullet behaviour. That means, I would have to rewrite everything and also, it will only turn in one side and not randomly left or right.
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Tue Mar 16, 2010 7:25 pm

I tried and I tried and I tried. I still can't get this stupid enemies to work, when there are two or more enemies.
Can anyone help me with those stupid tanks, please? :(

This is not a captcha. This is a .cap File
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Mon Apr 19, 2010 2:24 pm

Rise up from the grave!

Anyway, I now use the RTS Behaviour. I didn't know how to make him move randomly, so I just did this with the waypoint to put at x: random(640) and y: random(480).
Now the issue is, how can I make that it doesn't put the point in the wall? The enemy sometimes just goes in circles because he can never touch the waypoint.

If anyone has another way of random movement, than just post your idea. :P
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Thu Apr 22, 2010 5:58 pm

I think this needs some better explanation.

I made the enemies work with waypoints. Always when the enemy has reached the waypoint, a new waypoint gets added in the map.
The event would be:
>If Enemy stopped moving
->Add waypoint at x=random(640), y=random(480).

Now the problem would be, sometimes the waypoint would be added in the wall. Making the Enemy run in circles trying to go to the waypoint in the wall.

Here's a little animation showing my problem:
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Sun Apr 25, 2010 11:46 pm

Add an event after the add waypoint event -

+ System: While
+ Waypoint: Waypoint overlaps Wall
-> Waypoint: Set X to Random(DisplayWidth)
-> Waypoint: Set Y to Random(DisplayHeight)

So it will keep randomising the position until it no longer overlaps with a wall.
Totally untested, but I think it should work. I've used a similar technique in other software, in the past.

EDIT: Just looked a little deeper and realised your waypoint is not actually an object, but is an option on the RTS behaviour (which I've never used), so my solution above won't work. However, I'm confident the concept will work with a little tweaking - just use a 'while' to relocate the waypoint until a usable position is found. I'll see if I can come up with a proper solution.
B
2
S
2
G
3
Posts: 105
Reputation: 1,510

Post » Mon Apr 26, 2010 1:54 am

@GMG
Here's a modification of your solution that should work. :)

+ System: While
+ System: "Solid" at (Sprite[RTS].DestX, Sprite[RTS].DestY)
-> Waypoint: Set X to Random(DisplayWidth)
-> Waypoint: Set Y to Random(DisplayHeight)
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Mon Apr 26, 2010 5:18 am

[quote="R0J0hound":1hph0id4]@GMG
Here's a modification of your solution that should work. :)

+ System: While
+ System: "Solid" at (Sprite[RTS].DestX, Sprite[RTS].DestY)
-> Waypoint: Set X to Random(DisplayWidth)
-> Waypoint: Set Y to Random(DisplayHeight)[/quote:1hph0id4]

[size=150:1hph0id4]Holy $#!^[/size:1hph0id4]
Wait, you can evaluate a sprites attribute?
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Apr 26, 2010 5:53 am

[quote:2pn9fm58]+ System: "Solid" at (Sprite[RTS].DestX, Sprite[RTS].DestY)[/quote:2pn9fm58]
It's the System condition 'Object overlaps point'. And yes it works with an attribute instead of an object.
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Mon Apr 26, 2010 6:08 am

Wow. That's one for the wiki.

Edit:
Ok it works for move to position/ move to mouse, but not for waypoint.
Just as well I guess, all waypoint does is ensure pathfinding around solids, and can actually bog down the system.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

PreviousNext

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 10 guests