#Having trouble creating dash towards mouse pointer ability Godot

31 messages · Page 1 of 1 (latest)

obsidian meadow
#

Can you show the full code?

unreal escarp
obsidian meadow
#

try copying it as text and add ( ` ) three times at the start and end

#

like this: code goes here

#

lol... if you have an english keyboard is the key that's next to the 1

#

XDDDD

unreal escarp
#

idk bruh

obsidian meadow
#

it's ok

#

it just makes it look fancy

unreal escarp
#

I did it

obsidian meadow
#


#VARIABLES
var MouseDirection = get_local_mouse_position().normalized()
var IsDashing = false
var CanDash = true

#CONSTANT VARIABLES
const Gravity = 6000
const Speed = 1500
const DashSpeed = 3500
const JumpVelocity = -1900

#ONREADY VARIABLES
@onready var JumpBuffer = $JumpBuffer
@onready var CoyoteTime = $CoyoteTime




#PLAYER MOVEMENT
func _physics_process(delta):
    #GRAVITY
    if !is_on_floor():
        velocity.y += Gravity * delta

    #JUMP
    if Input.is_action_just_pressed("PlayerMovementJump"):
        if is_on_floor() || !CoyoteTime.is_stopped() && velocity.y >= 0:
            CoyoteTime.stop()
            velocity.y = JumpVelocity
        else:
            JumpBuffer.start()

    #MOVEMENT
    var Direction = Input.get_axis("PlayerMovementLeft", "PlayerMovementRight")
    if IsDashing:
        velocity = Vector2(MouseDirection * DashSpeed)
    else:
        velocity.x = Direction * Speed
    if !Direction:
        velocity.x = move_toward(velocity.x, 0, Speed)

    #COYOTE TIME
    var WasOnFloor = is_on_floor()
    move_and_slide()
    if !is_on_floor() && WasOnFloor:
        CoyoteTime.start()

    #JUMP BUFFER
    if is_on_floor() && !JumpBuffer.is_stopped():
        JumpBuffer.stop()
        velocity.y = JumpVelocity

    #JUMP HEIGHT
    if Input.is_action_just_released("PlayerMovementJump") && velocity.y < -500:
        velocity.y = -500

    #DASH
    if Input.is_action_just_pressed("Dash") && CanDash:
        IsDashing = true
        CanDash = false
        $Dash.start()
        $DashAgain.start()

func _on_dash_timeout():
    IsDashing = false

func _on_dash_again_timeout():
    CanDash = true
#

So basically you want to dash while is in the air?

unreal escarp
obsidian meadow
#

I'm trying to recreate the project so I can understand the behaviour of the character better

#

I noticed you have two checks for jump?

unreal escarp
#

that seciond opart checkas ofr if the player lets go eraly the you do a hsort hjujmp

obsidian meadow
#

hmm ok

#

I think I fixed it

unreal escarp
#

yippe

#

how

obsidian meadow
#

no wait... it's... doing something weird XD

#

.... at least it's following the mouse now

#

ok I think I messed up with the timers but basically what happened is that you assigned the position of the mouse at the start but never updated it, so the character was debating if either following the velocity of x or the original mouse pointer

#

try this code instead:

unreal escarp
#

that kinda working exspet its really buggy

#

ive modified ity and its working graet, thanks so much.

obsidian meadow
#

no problem. Glad I could help

unreal escarp
#

Sorry @obsidian meadow theres one promblem, when you dash if the curcers tpo close to the player it will glitch becuase the playwr will touch the curcer. It also dashes upwards reallt high but very little sidewyas.

obsidian meadow
#

when I did it it got stuck to my mouse pointer and wouldn't go away

#

try printing some of the variables so you can see how they behave, maybe that will give you an idea of what's not working

#

I believe it might have something to do with the timers. The dash timer might not be triggering properly