i am working on top down game and i need the player to push objects around
so i followed this tutorial
and it worked just fine until i tried pushing the object downwards, the player just sticks to as if gravity was involved but i have my default gravity set to zero
does anyone knows why that happens?
extends CharacterBody2D
var push = 150
@export var speed = 175
func _physics_process(delta):
handleInput()
if Input.is_action_pressed("move_right"):
$AnimatedSprite2D.play("right")
elif Input.is_action_pressed("move_left"):
$AnimatedSprite2D.play("left")
elif Input.is_action_pressed("move_down"):
$AnimatedSprite2D.play("down")
elif Input.is_action_pressed("move_up"):
$AnimatedSprite2D.play("up")
else: $AnimatedSprite2D.play("default")
move_and_slide()
for i in get_slide_collision_count():
var c = get_slide_collision(i)
if c .get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal() * speed)
func handleInput():
var movedirection = Input.get_vector("move_left","move_right","move_up","move_down")
velocity = movedirection * speed