Topic was automatically imported from the old Question2Answer platform.
Asked By
Juwu
I put a Position2D for the projectile for the player on my game, but the position that I put wasn’t the original, the position stays a little down and right from the original
the problem coud may be in your code where the projectile gets moved slightly
extends Node2D
var speed = 10
var ball = false
var up = false
var down = false
var left = false
var right = false
var proj = preload('res://Scenes/Ball.tscn')
func _process(delta):
move()
stop()
func move():
if Input.is_action_pressed("ui_right"):
position.x += speed
right = true
left = false
down = false
up = false
pass
if Input.is_action_pressed("ui_left"):
position.x -= speed
left = true
right = false
down = false
up = false
pass
if Input.is_action_pressed("ui_up"):
position.y -= speed
up = true
left = false
down = false
right = false
pass
if Input.is_action_pressed("ui_down"):
position.y += speed
down = true
left = false
right = false
up = false
pass
if Input.is_action_just_pressed("ui_select"):
var tiro = proj.instance()
get_parent().add_child(tiro)
tiro.position = $Player_2d/Position2D.global_position
func stop():
if position.x <= 20:
position.x = 20
elif position.x >= 1280:
position.x = 1280
if position.y <= 0:
position.y = 0
elif position.y >= 720:
position.y = 720