Physics or something
This commit is contained in:
1 parent
32f912df9e
commit
9a2e3d8b58
12 files changed
+293
-34
No files matched your search
+36
-12
@@ -1,24 +1,48 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
const SPEED = 400.0
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
const GRAVITY_MULT = 0.8
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
#if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
const JUMP_VELOCITY = -410.0
|
||||
|
||||
# Handle jump.
|
||||
#if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
#velocity.y = JUMP_VELOCITY
|
||||
var fall_timer = 0.0
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction := Input.get_axis("ui_left", "ui_right")
|
||||
var jumps = 0
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
if is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
elif !is_on_floor() and jumps >= 1:
|
||||
jumps -= 1
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
if Input.is_action_pressed("jump") and is_on_wall_only():
|
||||
print("WALL HANGING")
|
||||
#velocity.y = 0
|
||||
#velocity.x = 0
|
||||
|
||||
var direction = Input.get_axis("move_left","move_right")
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
fall_timer += 0.001
|
||||
if is_on_floor():
|
||||
fall_timer = 0
|
||||
jumps = 1
|
||||
|
||||
if is_on_wall():
|
||||
jumps = 1
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
||||
if not is_on_floor():
|
||||
velocity += (get_gravity() * GRAVITY_MULT) * delta
|
||||
|
||||
move_and_slide()
|
||||
Reference in new issue
Block a user