How would I make a CharacterBody2D move a certain amount of times in the direction the player is facing? I tried using the “for x in 10” and it did repeat that certain amount of times, but the velocity.x stayed the same and didn’t change.
I need a “dive” mechanic somewhat like in Mario 64. If you don’t know what I’m talking about you could look up some Mario 64 footage and it would make more sense.
Super Mario 64 increases your speed for a bit when you press A in the water, maybe you want to use a dampening function on your speed and increase it over the damp limit? Might be more helpful to paste your player controller’s script?
var dash_amount = 0.0
var dash_time = 5.0
var can_dash = false
var dash_speed = 100.0
func _physical_process(delta):
if can_dash:
dash_amount += dash_time * delta
if Input.is_action_just_pressed("dash") and can_dash:
can_dash = true
if can_dash: velocity.x = dash_amount * dash_speed
if dash_amount >= 1.0: can_dash = false
It is possible that I made a mistake, maybe because I wrote it in mobile.
Also, it is just a simple time/amount based dash, I not watched any Mario 64 footage (will watch later)
I was talking more like a long jump of sorts when your player is on the ground. My code just consists of basic character movement like a velocity.x and velocity.y variable and since I’m new I wouldn’t know how to control those in the long run.
The CharacterBody2D template script? Then what I am talking about is similar to how it applies jumps/gravity.
The jump is the extra force being applied, notice it’s faster than SPEED. The dampening is applied via gravity, a subtractive force over time.
You could do the same thing on the x axis as jump/gravity does on the y. Make sure to change your velocity to use move_toward and delta like so, using a new constant ACCELERATION and DECELERATION
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = move_toward(velocity.x, direction * SPEED, ACCELERATION * delta)
else:
velocity.x = move_toward(velocity.x, 0, DECELERATION * delta)