![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Marline |
I tried to make a fake collision in my game but it didn’t work…so after adding gravity in Sprite…it has fallen and stayed at bottom of the platform but instead of being at the bottom of the platform screen…it goes beyond it.so I tried to find out where is the issue. So if anyone can help me to find out my problem…Down below is my code.
extends Node2D
onready var animated_sprite = $AnimatedSprite
var velocity = Vector2.ZERO
var max_run = 100
var run_accel = 800
var gravity = 1000
var max_fall = 160
func _process(delta):
var direction = sign(Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left"))
if direction > 0 :
animated_sprite.flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
if direction != 0:
animated_sprite.play("Run")
else:
animated_sprite.play("Idle")
velocity.x = move_toward(velocity.x, max_run * direction, run_accel * delta)
velocity.y = move_toward(velocity.y, max_fall, gravity * delta)
global_position.x += (velocity.x * delta)
global_position.y += (velocity.y * delta)
if global_position.y >= 160:
global_position.y = 160