YesNoOk
avatar

Lock On Dash Attack (Read 20310 times)

Started by Plum, March 04, 2023, 07:11:24 pm
Share this topic:
Lock On Dash Attack
#1  March 04, 2023, 07:11:24 pm
  • **
  • Variables > Boyfriends
I have a character that jumps in the air and charges while holding a lance/spear for about two seconds before dashing either forward or diagonal. Could anyone give me an idea on how to make her charge to where the enemy is standing/ jumping etc one second BEFORE the charge? Not homing or chasing, but one line of direction.

For example: If the enemy is in the air across from you as you're charging the dash, the moment you release you would just shoot forward; and If they were below you at an angle, you shoot diagonally-no curving or chasing. I'd like to know if there is a way to "check" enemy location and then burst towards them?
Re: Lock On Dash Attack
#2  March 05, 2023, 01:45:26 am
  • *****
  • Shame on you!
    • USA
This shouldn't be too hard. You could set variables, or spawn an invisible helper.

This is the code I use to track the enemy's chest approximation.

Code:
[State 1350, Chest Finder]
type = VarSet
trigger1 = (Time%1) = 0
v = 12    ;fv = 10
value = floor( (enemy,const(size.head.pos.y) - enemy,const(size.mid.pos.y) )/2 )

[State 1350, Chest Tracker]
type = VarSet
trigger1 = (Time%1) = 0
v = 13    ;fv = 10
;value = floor( const(size.mid.pos.y) +  var(12))
value = ifelse(enemynear(0), statetype = L , 10, ifelse(enemynear(0), statetype = C ,floor( enemy,const(size.mid.pos.y)/2), floor( enemy,const(size.mid.pos.y) +  var(12))))

[State 1350, GO]
type = VarSet
trigger1 = (Time%1) = 0
v = 10
value = ceil(P2BodyDist Y + var(13)  )/20;10   
If you're not trying to do all that, Var(10) could be edited so var(13) is just p2 body distance x. But that'll aim at it's "feet"

This is the code to make it go.
Code:
[State 1350, RELEASEtheHounds]
type = Velset
triggerall = P2Dist X > 0 ;whered it go?
triggerall = time >= 7 ;out of the gun
triggerall=Time<=125 ;fuel supply
trigger1 = (Time%1) = 0
trigger1 = var(10) = [1,-1]
y = 0

[State 150, RELEASEtheHounds]
type = Velset
triggerall = P2Dist X > 0 ;whered it go?
triggerall = time >= 7 ;out of the gun
triggerall=Time<=125 ;fuel supply
triggerall = (Time%1) = 0
trigger1 = var(10) = [-8,-1.1]
trigger2 = var(10) = [1.1,8]
y =  var(10)/2  ;exact spot of chest

You can see my missile updates every tic. You can set it to 1 particular tic and it'll work the way you want.
If you want it to have an overall speed, you would use something like
x = (14-vel y).
for the vel x. Otherwise if you're doing like a light, medium, heavy, you could just do x = 3,5,7 or whatever.
This all updates fast. So the only thing you should have to change is setting the vels at the tic you want and it should fire toward the enemy.
vVv Gouken718 vVv
Re: Lock On Dash Attack
#3  March 05, 2023, 09:53:58 pm
  • **
  • Variables > Boyfriends
First of all, thanks for the reply.~
I spent a few hours trying to understand the code and I'm still at a loss. I use var(10) ifelse already to adjust velset,I ended up change it to var(15) so I could test out your code since I didn't want to have a million states--plus I try to avoid var as much as possible and I want to stop making a so many states as a crutch, unless it's super necessary.

When I use your code I shoot at P2's head, which is kinda cool, but then the character sorta bounces and keeps going, never going for a straight shot--after I reach the "head" she doesn't ever touch the ground. I adjusted the fuel supply and (Time%1) but I just couldn't get the results I wanted. I'm pretty sure I'm missing something simple but I'd like to try this method over tracking helpers.

I was trying to emulate the lock on at 0:30, 0:34, & 0:52
https://www.youtube.com/watch?v=PZecYa4OCmo&ab_channel=PCIndieMasterRace
Re: Lock On Dash Attack
#4  March 05, 2023, 10:24:53 pm
  • ****
    • Brazil
    • lyricasky.neocities.org
I made a quick test and this seems to work, but you'll need to tweak the velocities a little:

Code:
[State 0, VelSet]
type = VelSet
trigger1 = Time = 10
x = P2Dist X / 30
y = (P2Dist Y - Enemy, Const(size.mid.pos.y)) / 50

It's simple and don't use variables.

Edit: oh, and if you want the character to fall after some time, you can use something like this:

Code:
[State 0, Gravity]
type = Gravity
trigger1 = Time >= 50 ; adjust the timing to your like

[State 0, ChangeAnim] ; Falling
type = ChangeAnim
trigger1 = Anim != 41 && Time >= 50 ; use the same time as above
value = 41

[State 0, ChangeState] ; Landing
type = ChangeState
trigger1 = Pos Y > -Vel Y
value = 52
Last Edit: March 05, 2023, 10:58:48 pm by DeathScythe
Re: Lock On Dash Attack
#5  March 07, 2023, 09:53:11 am
  • *****
  • Shame on you!
    • USA
DeathScythe, Plum wants a delay on the attack. So if P2 moves it'll fire toward the old spot. I think your code is set up to fire off where P2 currently is.

So [State 1350, Chest Finder] you might not want or need at all. Just depends on where you want your move to aim on P2.
In [State 1350, Chest Tracker]
value = ifelse(enemynear(0), statetype = L , 10, ifelse(enemynear(0), statetype = C ,floor( enemy,const(size.mid.pos.y)/2), floor( enemy,const(size.mid.pos.y) +  var(12))))
can be broken up into chunks to read easier.
ifelse(enemynear(0), statetype = L , 10,    Means if P2 is laying on the ground, aim 10 pixels above the floor.
ifelse(enemynear(0), statetype = C ,floor( enemy,const(size.mid.pos.y)/2),    Means if P2 is crouching, aim halfway up to the middle of it's body. AKA their knee's height. Just a general spot for crouch height.
floor( enemy,const(size.mid.pos.y) +  var(12)   Means  floor( (enemy,const(size.head.pos.y) - enemy,const(size.mid.pos.y) )/2 )+enemy,const(size.mid.pos.y)  AKA halfway between their head and their mid position.
So it's saying if p2 is laying down, aim 10 pixels up, if theyre crouching aim at their knees, and in every other situation find their midspot and aim up a little.
 

It sounds like you just need to "end" the move a little sooner. If it keeps going, Stop? You'll need a hit state and a state to end everything. If it's an air move, you'll also want a land on the ground state. And if it hit's p2 in the air you'll need that and a landing state after that. But you could use the other two states and check the prevstateno and adjust your values to match.

You shouldn't be using my code exactly.
triggerall=Time<=125 ;fuel supply
trigger1 = (Time%1) = 0
both of these should be combined into 1 trigger for the exact moment you want. Time = 30 maybe?

Your changestate needs a check to see how far you are from P2. something like
P2BodyDist Y + P2BodyDist X <= 14
So that if it's 6 pixels up and 8 pixels over, that's close enough. It sort of makes a radius from P2. Adjust the 14 until you get the distance you like.
You'll also want to check if it's at a pos y, and how long it's been flying for. Time >=120 or something similar so it doesnt get stuck doing the move for forever is always a good idea.
vVv Gouken718 vVv
Last Edit: March 07, 2023, 09:58:25 am by Odb718