Problem with angle of enemies, please help :P

Discussion and feedback on Construct 2

Post » Wed Dec 31, 2014 4:52 pm

Hi guys!! i want to see if you could give me a hand with this one, see i ahev these enemies follow my player, but if you stay diagonal to them and let them get near you, the angle will change constantly and the will start spazzing out

i have a variable to determine the angle beetween the player and the enemy and with that i determine the way they should be looking (wich animation) i really dont know how to make the enemies go diagonal and dont change animation so weirdly

i hope you guys can help me :P
You do not have the required permissions to view the files attached to this post.
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Wed Dec 31, 2014 5:15 pm

Sorry, I couldn't open the .capx, I'm still on v190 - Which behaviour are you using for the motion ? Bullet ? Path planning ? Custom ?

If you're using a Bullet-type movement, you can get a simple but effective "follow" behaviour with just something like :

Code: Select all
Enemy | Set Bullet angle of motion to angleRotate(Enemy.Bullet.AngleOfMotion, angle(Enemy.X, Enemy.Y, Player.X, Player.Y), angularVelocity*dt)

with angularVelocity a variable you control to cap the turn rate in degrees/sec to prevent entities from turning too quickly at short angles and get nicer trajectories.

As for getting too close to the target, I would suggest handling that with a simple finite state machine :
state 1 - far from the target > use the Bullet/Follow behaviour ; if close to target, switch to state 2
state 2 - close to the target > do something else (short range attack, etc.) ; if far from the target, switch to state 1

A "follow"-type navigation behaviour when close to the target will always cause problems (overshooting, spazzing out when trying to correct, etc.)

'hope that helps !
Image
Game Producer & Independent Developer - http://raphaelgervaise.com
B
23
S
9
Posts: 237
Reputation: 2,207

Post » Wed Dec 31, 2014 11:52 pm

Use a different set of angles when they are within X distance to the target (e.g. 350 to 0 and 0 to 10 means look sideways when far away but 280 to 0 and 0 to 80 means look sideways when close)... also can change the speed of how often they change direction when close vs far.
B
21
S
5
Posts: 196
Reputation: 1,974

Post » Thu Jan 01, 2015 9:57 am

@Refeuh

thanks n.n you gave me some ideas, but not what im looking for, you would need to open the .capx
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Thu Jan 01, 2015 10:04 am

@ggibson1

could you explain a little better? or maybe show me with the .capx? it would be apreciated :P

i need help with this, the angle on wich the enemies turn towards me, varies constantly when going diagonally, so it goes like (North, North East, North, North East, North, North East, North, North East) and that why it starts spazzing out
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Thu Jan 01, 2015 10:20 am

Ok i made a work around, insted of moving in by the angle beetween the player and the enemy, im gogin to set the animation to the angle of motion, to see if it works, be back :)
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Tue Jul 12, 2016 9:21 am

Lunatrap wrote:Ok i made a work around, insted of moving in by the angle beetween the player and the enemy, im gogin to set the animation to the angle of motion, to see if it works, be back :)


Is it working?
B
9
S
4
G
1
Posts: 18
Reputation: 1,315


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests