Hi all!
I am stuck on a piece of my code that is driving me crazy. Hopefully someone here can help. I have two nodes that I want to interact with each other. One is a kematicbody2d Player node (called "Lizard") the other is an area2D ("Light"). What I want to do is when the player enters the area2d, it starts tracking the player's current position. When player leaves the light, it stops.
Right now I am able to print the player's position upon entering the Area2D node, however it only prints the INITIAL position at game start, not the current position. I am using var "loc" to get my player's position in the Lizard code. If I set the variable in the _fixed_process(delta) function, when I try to print it in Area2D it doesn't print anything. If I set var loc outside of process delta, it only gives me the start position of the node and doesn't update.
Lizard Code:
extends KinematicBody2D
export var speedmult = 10
export var MOTIONSPEED = 500
func _ready():
---set_fixed_process(true)
func _fixed_process(delta):
---var loc = self.get_pos()
---var motion = Vector2()
---#get_node("Light").Brightness
<i> movement</i>
---if(Input.is_action_pressed("move_up")):
------motion += Vector2(0,-1)
---if(Input.is_action_pressed("move_left")):
------motion += Vector2(-1,0)
---if(Input.is_action_pressed("move_down")):
------motion += Vector2(0,1)
---if(Input.is_action_pressed("move_right")):
------motion += Vector2(1,0)
---if(is_colliding()):
------print("hi")
------#print(Light.Brightness)
---motion = motion.normalized() * MOTIONSPEED * delta
---move(motion)
---#print(get_pos())
<b>Light code:</b>
extends Area2D
export var Brightness = 2
onready var getLizard = get_node("/root/World/Lizard").get("loc")
func _ready():
---self.set_scale(Vector2(Brightness,Brightness))
---set_process(true)
func _process(delta):
---self.set_scale(Vector2(Brightness,Brightness))
func _on_Light_body_enter_shape( body_id, body, body_shape, area_shape ):
---print(getLizard, "Hello")
func _on_Light_body_exit_shape( body_id, body, body_shape, area_shape ):
---print("Goodbye")
**********************
Any help appreciated, I've been stuck on this for DAYS.