Hello I’m not sure if I’ve found a bug or not if someone could take a look. I’m not super familiar with godot and am fairly new so it could be user error.
If I type specific numbers it causes the player to move off screen as seen in recording. I discovered this when trying to use the collision shape size of an object in place of the 75 I replaced in the recording.
Thanks for taking a look!
class_name PickupScript extends Area2D
var player_in_node : bool = false
var parent : Node2D
var body : CharacterBody2D
var preview_object : bool = false
var collision_shape_size : Vector2
func _ready() -> void:
body_entered.connect(_body_entered)
body_exited.connect(_body_exited)
parent = self.get_parent()
for c in parent.get_children():
if c is StaticBody2D:
for _c in c.get_children():
if _c is CollisionShape2D:
collision_shape_size = _c.shape.size
func _input(event: InputEvent) -> void:
if event.is_action_pressed(&"interact") and player_in_node == true and preview_object == false:
print(&"interacting")
get_viewport().set_input_as_handled()
parent.modulate = Color(0.227, 1, 0, 0.361)
preview_object = true
elif event.is_action_pressed(&"interact") and preview_object == true:
parent.modulate = Color(1,1,1,1)
preview_object = false
func _physics_process(delta: float) -> void:
print(collision_shape_size.x)
var b : int = collision_shape_size.x
if preview_object == true:
if body is Player:
if body.cardinal_direction != Vector2.DOWN:
parent.global_position = body.global_position + (body.cardinal_direction * 75)
else:
parent.global_position = body.global_position + (body.cardinal_direction * 50)
func _body_entered(_body:CharacterBody2D) -> void:
player_in_node = true
body = _body
pass
func _body_exited(_body:CharacterBody2D) -> void:
player_in_node = false
pass