Godot Version
Godot Engine v4.4.1.stable.steam.49a5bc7b6
Question
I am trying to implement a “dash” mechanic and i am a little confused on how to make the direction of velocity boost be the same direction of this raycast (for example).
(It doesn’t need to be a raycast necessarily, as long as the velocity boost on the player has the same direction as shown above)
You need to take the transform, or global_transform and use the basis vector x, or y, depending on what you consider the “front” of the sprite. Since the basis vector is normalized, meaning its length is one, you multiply it by your speed, or acceleration, constant to move in the direction of the current rotation.
For Transform2D they dont call it a basis but just x and y. And every Node2D has a transform and global_transform property.
I would suggest always using global coordinate variables, unless you have a specific reason to do it in local space.
2 Likes
Should i get the values something like this?
I tried implementing the code and it worked.
(Even though it goes from 0 to 2, instead of 0 to 1)
The script:
extends Node2D
@export var DashPanelIntensity: float = -100
func _process(delta: float) -> void:
if Global.IsDashPanel:
Global.DashPanelForce = get_global_transform().y * DashPanelIntensity
print(Global.DashPanelForce)
1 Like