Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | AegisCZ | |
Old Version | Published before Godot 3 was released. |
I’m trying to make a 2d top-down Factorio-like game.
I’m having some problems with the player colliding with other objects.
The player uses kinematic-body while rocks use static-bodies. I can’t get the player to collide with the rock.
extends Node2D
var Position
const SpeedVert = 3
const SpeedHor = 3
func _ready():
set_process(true)
func _process(delta):
Position = get_pos()
if Input.is_action_pressed("ui_up"):
Position.y -= SpeedVert
if Input.is_action_pressed("ui_down"):
Position.y += SpeedVert
if Input.is_action_pressed("ui_left"):
Position.x -= SpeedHor
if Input.is_action_pressed("ui_right"):
Position.x += SpeedHor
if (not get_node("PlayerBody").test_move(Position)):
# get_node("PlayerBody").move(Position)
set_pos(Position)
Please help