Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | edimemune | |
Old Version | Published before Godot 3 was released. |
I am learning Godot game engine and I tried to make a ball that can walk and can’t go through other objects, but the ball keep going through the other objects.
Here is the code:
extends KinematicBody2D
export var viteza = 140
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
delta *= 5
var motion = Vector2()
if Input.is_key_pressed(KEY_UP):
motion[0] = 0
motion[1] = -1
if Input.is_key_pressed(KEY_DOWN):
motion[0] = 0
motion[1] = 1
if Input.is_key_pressed(KEY_LEFT):
motion[0] = -1
motion[1] = 0
if Input.is_key_pressed(KEY_RIGHT):
motion[0] = 1
motion[1] = 0
motion = motion * viteza * delta
set_pos(get_pos() + motion)
What is wrong?