![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | lorolom |
Hello, everyone, i have a problem: after watching a tutorial about making a platformer game i wanted to make an additional trap to it, in the idea it should fall down, wait a few seconds and jump, but instead of the jump it’s just little shaking.
Trap code:
extends Actor
export var jump_force: = 50.0
func _physics_process(delta: float) -> void:
velocity.y += gravity * delta
if is_on_floor():
$Timer.start()
velocity.y = _on_Timer_timeout(velocity,jump_force).y
velocity.y = move_and_slide(velocity, FLOOR_NORMAL).y
func _on_Timer_timeout(linear_velocity: Vector2, impuls: float) -> Vector2:
var out: = linear_velocity
out.y = -impuls
return out
Actor code:
extends KinematicBody2D
class_name Actor
const FLOOR_NORMAL: = Vector2.UP
export var speed: = Vector2(300.0, 1000.0)
export var gravity: = 3000.0
var velocity: = Vector2.ZERO
(Apologize in advance for unreadable code, using Q&A for first time.)
if your trap is on the floor then start the timer
the timer gets constantly started every frame if it is on the floor
so since it keeps getting started it doesn’t actually finish which means it never jumps
OgGhostJelly | 2023-01-07 15:06