![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Andyroo |
Im very new to programming thats been trying to create a 2D rpg game and ive been using tutorials to do specific tasks in godot and ive seem to run into a problem… I cannot move my 2d character but the animation is still going (on the spot) im not sure where and how to put the scripts, should i put them together or leave them seperate (animation and moving)
Animation script:
extends KinematicBody2D
#Called when the node enters the scene tree for the first time.
func _ready():
$AnimationPlayer.play(“walk_down”)
func _physics_process(delta):
if Input.is_action_pressed(“down”):
$AnimationPlayer.play(“walk_down”);
elif Input.is_action_pressed(“right”):
$AnimationPlayer.play(“walk_right”);
elif Input.is_action_pressed(“up”):
$AnimationPlayer.play(“walk_up”);
elif Input.is_action_pressed(“left”):
$AnimationPlayer.play(“walk_left”);
Movement script:
extends KinematicBody2D
var velocity : Vector2 = Vector2()
var direction : Vector2 = Vector2()
func read_input():
velocity = Vector2()
if Input.is_action_pressed("up"):
velocity.y -= 1
direction = Vector2(0,-1)
if Input.is_action_pressed("down"):
velocity.y += 1
direction = Vector2(0,1)
if Input.is_action_pressed("right"):
velocity.x += 1
direction = Vector2(1,0
)
if Input.is_action_pressed("left"):
velocity.x -= 1
direction = Vector2(-1,0)
velocity = velocity.normalized()
velocity = move_and_slide(velocity * 200)
func _physics_process(delta):
read_input()
Ive attached the movement script to the KinematicNode2D in the player.tscn (player scene) and the animation script to the KinematicNode2D in the main.tscn (main scene)