#M1 dash mechanic not correctly working

1 messages · Page 1 of 1 (latest)

ruby cloud
#

i have an m1 system for my hack-and-slash game where the player dashes forward if an enemy is 20 studs in front of the player in a 30 degree scan. usually, the player would correctly dash to be in front of the enemy, but in specific cases (i think it has something to do with the distance of the enemy compared to the player), the player is frozen in place, and if the player's back is facing a wall at certain angles, the player will move to the top of the wall.

this is what it looks like when against a wall

#

here is what happens when i turn anchored on and off while frozen in place against a wall (if anchored on the ground which is rarer it will not do anything)

ruby cloud
ruby cloud
# ruby cloud

the other 3 m1s have the same dash logic just a different animation timeposition and CreateHitbox logic

verbal moat
#

@ruby cloud are there any errors

ruby cloud
#

nothing is wrong the logic is just bad

verbal moat
#

btw protip you shouldnt use raycasting for that, you can directly get the angl thru the acos of cameraLookVector:Dot(<direction of your character to enemy>)

#

so

#

when you get the dot product

#

you acos it

#

and it returns the degrees between the two vectors in radians

ruby cloud
verbal moat
#

you can directly just do math.deg after getting acos

verbal moat
#

to the client

ruby cloud
#

man

#

wait

#

its not even dependent on the camera

#

it depends on which way the hrp is facing

verbal moat
#

so you dont have to worry about that

ruby cloud
verbal moat
#

loop thru all the enemies

ruby cloud
#

the raycast is to see if the dash should even happen in the first place

verbal moat
#

distance check

#

if its within distance

#

dot

ruby cloud
verbal moat
#

??

ruby cloud
#

idk

#

its like 1 am

verbal moat
#

dawg

ruby cloud
#

ive been working on this for 14 hours

verbal moat
#

distance check first so you dont waste resources on doing the dot calculation

ruby cloud
#

this will still be very fast even if there are like 30 enemies spawned?

verbal moat
#

probably

#

more likely than nost

#

definitely a wayyy more optimized and less performance heavy alternative

#

than 30 raycasts

ruby cloud
#

its actually 15 raycasts i sent a slightly out of date version

#

but alr

#

hold on

verbal moat
ruby cloud
verbal moat
#

yes

#

make sure v is .unit

ruby cloud
#

ok

verbal moat
#

so (p1 - p2).Unit

#

you know why right

ruby cloud
#

now about the actual dash

ruby cloud
verbal moat
#

ok

ruby cloud
#

how do i make it so that it doesnt break like in the videos

verbal moat
#

or stick to here

ruby cloud
verbal moat
#

alr

#

valid

#

youre sure there arent any errors?

ruby cloud
#

yep

verbal moat
#

is the issue still there

ruby cloud
#

yea

#

its in the if target then statement

verbal moat
#

why do you make local ready = true

#

just to set it false after

ruby cloud
#

so that the attack doesnt happen until the player is done dashing

#

?

#

wdym

verbal moat
#

oh i see

#

nvm

#

is there even actual dash logic

#

or is it just moving you to

#

a spot

ruby cloud
verbal moat
#

oh

#

i thought that said hum:moveto

#

whoopsioe

ruby cloud
#

lol

verbal moat
#

thats likely your issue

ruby cloud
#

nah

verbal moat
#

yeah

ruby cloud
#

alr

verbal moat
#

try it

#

tell me what happens

ruby cloud
#

its inconsistent so it might take a bit

#

hold on

meager sluiceBOT
#

studio** You are now Level 27! **studio

ruby cloud
#

ok so it still places the player up where it would usually freeze against the wall but i get unanchored

#

nvm

#

it still breaks

#

the midair freeze was cuz i forgot to fix the other m1 logics but i get anchored on the ground a lot more frequently now

#

here is JUST the dash logic if you need it

                local ready = true
                if target then
                    local eHum = target:FindFirstChildOfClass("Humanoid") :: Humanoid
                    local eHrp = target:FindFirstChild("HumanoidRootPart") :: Part
                    
                    local P = (eHrp.Position - hrp.Position)
                    local mDist = 6
                    if Vector3.new(P.X, 0, P.Z).Magnitude > mDist then
                        ready = false
                        hrp.Anchored = true
                        local DashConn
                        DashConn = RunService.Heartbeat:Connect(function(dt: number)
                            if not target or eHum.Health <= 0 or hum.Health <= 0 then
                                ready = true
                                DashConn:Disconnect()
                                return
                            end

                            local dir = (eHrp.Position - hrp.Position)
                            local dist, hor = dir.Magnitude, Vector3.new(dir.X, 0, dir.Z).Magnitude

                            if hor <= mDist then
                                ready = true
                                DashConn:Disconnect()
                                return
                            end

                            local moveDirection = dir.Unit * math.min(dist - 4, dt * 100)
                            chr:MoveTo(hrp.Position + Vector3.new(moveDirection.X, 0, moveDirection.Z))
                        end)
                    end
                end
                
                repeat task.wait() until ready
verbal moat
#

@ruby cloud

#

add a print in the repeat statement

#

and see if the issue is that statement holding up the rest of the code

ruby cloud
#

print ready?

verbal moat
#

when you get stuck

#

if it repeatedly prints 1, then your issue is there

ruby cloud
#

nope

#

i was printing ready so when it prints true i should be free to move

#

but when the anchor glitch happened it printed true

#

watch this be something stupid like i just forgot to unanchor the player

#

i might lose my mind if thats actually why

#

.

#

ur not gonna fucking believe it

#

i forgot to put hrp.Anchored = false in the other m1 functions

#

:(

verbal moat
#

hey