Godot Version
4.4.1
Question
I have a Particles2D that is supposed to be launched upwards when the player (CharacterBody2D) hits the ground. The direction is lined up (-1 y) and everything, but for some reason when the particles are emitted they go down a fair amount before going back up as usual. I’d attach a video but a link will suffice since I am a new user. Video link here → https://youtu.be/7_ROb7V422w
As you can see, other (very similar) particle effects don’t seem to do this.
The code for the ability looks like this:
extends Node
class_name SlamComponent
enum SLAM_STATE {
SLAMMING,
HOVERING,
IDLE,
}
@export var min_height_px : float = 45.0
@export var slam_speed := 1000.0
@export var ground_ray : RayCast2D
@export var hop_force : float = 30.0
@export var float_time := 0.3
var body_high_enough : bool = false;
var slam_state : SLAM_STATE = SLAM_STATE.IDLE
func _ready() -> void:
ground_ray.target_position.y = min_height_px
func is_near_ground() -> bool:
return ground_ray.is_colliding()
func handle_slam(body : Player, slam_input : bool) -> void:
body_high_enough = not is_near_ground();
match slam_state:
SLAM_STATE.IDLE:
if slam_input and body_high_enough:
body.velocity.y -= hop_force
slam_state = SLAM_STATE.HOVERING
SLAM_STATE.HOVERING:
body.gravity_component.gravity_scale = 0.1
await get_tree().create_timer(float_time).timeout
print("slamming")
body.velocity.y = slam_speed
body.velocity.x = 0 # Lock horizontal
slam_state = SLAM_STATE.SLAMMING
SLAM_STATE.SLAMMING:
if body.is_on_floor():
body.gravity_component.gravity_scale = 1
_on_slam_impact(body)
func _on_slam_impact(body:Player) -> void:
slam_state = SLAM_STATE.IDLE;
body.shake_camera.add_trauma(0.05)
print("SLAM!")
body.gp_particles.restart()