Turret Issues

Get help using Construct 2

Post » Mon Nov 18, 2013 6:55 pm

So I'm new to turrets and this is my first time setting one up. I just can't seem to get it working though. I have a Squirrel enemy that I want to throw acorns at the hero so I figured a turret would be ideal as it has targeting and range options. When I set it up nothing happens at all if I have rotate turned off. If I have rotate turned on the squirrel rotates until it's back is turned to me and starts throwing acorns perfectly. I'm guessing there is a way to tell Construct what the front of the turret is, but I have no clue how. And no clue as to why it doesn't work at all if rotate is turned off. On a side note, is there a way to have the acorns destroyed if they collide with anything, not just a specific object?

Any ideas are appreciated.


EVENT SHEET

Image
B
47
S
17
G
3
Posts: 206
Reputation: 5,061

Post » Mon Nov 18, 2013 9:59 pm

The right side of your image (in image editor) will be the front.

Check for collides with multiple sprites: use a family for that OR an OR-block if you are using the free version of construct 2

no idea why it would work with rotation and wouldnt work without rotationmindfaQ2013-11-18 22:00:44
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Fri Nov 22, 2013 2:03 am

So I found a solution for my specific issue. I decided to can the turret features as they eluded me and just went with good ol' fashion programing to get it going. With this bit of code it allows the player to enter a preset range, the enemy will turn face the player and throw and object that hurts the player. Below is an event sheet on how I was able to achieve it. If anyone has thoughts on how to streamline the code for efficiency please let me know.



In this, the Hero is the player, Acorn is the throwable object, squirrel is the enemy, and range is an invisible red box surrounding the squirrel.
Image
B
47
S
17
G
3
Posts: 206
Reputation: 5,061

Post » Fri Nov 22, 2013 2:32 am

It is not optimal since every 1 seconds uses the global time, so it will happen that the squirrel will not fire the bullet immediately when you come into range. That might not seem that big of a deal in this case, but in other cases where the time intervall is bigger (like 5 seconds) this becomes really inconsistent.

I'd prefer a construction like (cd = instance variable of squirrel):

every tick
cd > 0: substract dt from cd

distance(hero.x,hero.y,squirrel.x,squirrel.y) < range AND cd less or equal 0: fire bullet, set cd to (your cooldown time)
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Fri Nov 22, 2013 4:01 am

I did notice what you mentioned that the squirrel does not react immediately when the hero enters the range, which is what I want. I will have to give your code a try and see if I can get it to work better. Thanks for the input it is HIGHLY appreciated, you have no idea.
Image
B
47
S
17
G
3
Posts: 206
Reputation: 5,061


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 35 guests