How do I make an object patrol an area?

Get help using Construct 2

Post » Thu Mar 27, 2014 6:36 am

Hi there.

My problem is in short that I want to have an object be able to sort of... patrol a certain area. They don't necessarily need the AI to chase after something, but what I would like is for say an enemy to be able to travel in some area and shoot lasers (think like an invader from Space Invaders) while doing so with full control over where they face and where they move (the actual shooting algorithm I've got down).

Specific examples:

- Moving in a horizontal line left and right; note that this isn't necessarily between two objects (it could be between two arbitrary points in space) and that I have to watch how many objects I'm using so adding in a ton of little solid objects to collide with and having them bounce off them or whatever is not preferred and if possible I'd really like to avoid it.

- Once the above is done, going vertically should be no problem

- After that, moving in a V shape and a square/box shape would be nice

- Moving in a circle would be a final great thing but it's not necessary at all, I'd rather get everything else working and this would just be a bonus if it happens to be relatively easy.

I tried doing a check for collisions but I have this problem where it checks for the collision, reverses the direction, and presumably ends up colliding with the same object again right after, and so it doesn't keep going in that direction... and I spent a while tweaking it and trying to think up weird solutions but in the end forfeited here because I think there should be a pretty easy way to do this and that I simply can't think of it and ultimately none of my solutions really worked, nevermind how tedious and inefficient they were turning out to be.

Some notes:

- my code's pretty much totally broken now and just has a foreach loop for every "MovingTurret" and also checks if it's on screen (I say don't bother moving turrets that can't be seen)

- I have an object limit and I'm trying to keep things relatively efficient in order to keep the framerate up amongst other things. Inserting a bunch of fake collider walls is not only inefficient but tedious given how many of these I could end up having.

- They don't all have to work the same way, I can create multiple separate objects for each type of movement if needed (though I'd prefer the linear movements work for the same object type...).

- I'm currently using an 8 directional movement behavior but if something else is better for this, by all means, I guess.

Let me know what I can do to help you help me, haha. I did some searches here but couldn't really find what I was looking for, so sorry if something almost exactly like this has been asked before (I feel like it probably has but eh...). Thanks!
B
19
S
10
Posts: 51
Reputation: 1,675

Post » Thu Mar 27, 2014 6:45 am

Sine behavior do exactly what you want. You may work your events with this behavior. Pathfind is a good option too.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Thu Mar 27, 2014 11:05 am

Well, that's certainly a helpful lead. I don't really get how it works but I'll play around and see what I can do and bump this if I have any more specific questions or something. Thanks =)
B
19
S
10
Posts: 51
Reputation: 1,675

Post » Thu Mar 27, 2014 11:24 am

Multiple Sine disabled at start, enable when you need it.

For moving in a circle, simple with Bullet (Set Angle Yes) with Rotate.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,616

Post » Tue Nov 25, 2014 4:09 pm

Hello, and how could I make that (with Sine behavior) when the object is at the end of the "sine", turn mirrored and go to the opposite way?
B
7
S
1
Posts: 28
Reputation: 652


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 7 guests