YesNoOk
avatar

Track enemy while following an arching path (Read 1178 times)

Started by SaltAddict, December 07, 2019, 07:19:24 pm
Share this topic:
Track enemy while following an arching path
#1  December 07, 2019, 07:19:24 pm
  • avatar
  • ***
    • Portugal
I'm coding a move where my characters tracks down the enemy and flies towards them (i.e if the enemy is on the ground and he jumps my character will move up, if he's on the air and he falls, my character will move down, etc...).

The normal version works fine, however, for the strong version I want my character to move up in an arc WHILE moving towards the enemy, and the angle of the arc needs to be adjusted mid-flight in case the enemy's x or y position changes.

Code:
[State ****: VelSet]
type = VelSet
trigger1 = time > 5
x = ((P2Dist X * 14) / (Exp(0.5*ln((P2Dist X * P2Dist X) + (P2Dist Y * P2Dist Y)))))

[State 0, Arc]
type = VelSet
trigger1  =time = 6
y = (((0.5*Const(movement.yaccel))-((enemy,pos x))-(pos Y)+(Enemynear,pos Y))) / -75 ;Fallback code

The code right now, the problem with it is that angle of the arc can't be adjusted after the char starts moving, I've tried to adjust it but can't seem to get it to work, I'm not very good at maths :/

Is this even possible?

Re: Track enemy while following an arching path
New #2  December 19, 2019, 04:29:20 am
    • Chile
This is what I did based in what you asked, although I'm not sure if this is what you want. It's kinda inspired by control systems used in engineering

Code:
[State X, VelSet]
type = VelSet
trigger1 = 1
x = -0.05*(pos x - (enemy, pos x))*facing
y = -0.04*(pos y - (enemy, pos y))

0.05 and 0.04 here are coeffcients you can tune to control how fast will the player try to reach some point in the stage, in this case the opponent, and also whether the curve's concavity will point upwards or downwards (try replacing 0.05 and 0.04 with 0.08 and 0.03 respectively in example). Try not to make them greater or equal than 1.

Here's a rather rudimentary demonstration of this state controller at work.

I'm writing a MUGEN engine from scratch. If you want to talk about it be free to send me a message!
Last Edit: December 19, 2019, 04:44:47 am by OpossumDaemon