I want to interact when i am inside on an object

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AllanOnAir

extends Area2D

var is_inside = false

func interact():
if Input.is_action_just_pressed(“Interaction”):
print(“Interagie”)

func _on_Porte_body_entered(_body):
is_inside = true
if is_inside == true:
interact()
pass

:bust_in_silhouette: Reply From: deaton64

Hi,
I think your code isn’t working as the body entered func is called once and so there isn’t enough time to call interact()

This is untested, but do something like:

extends Area2D

var is_inside = false

func _process(_delta: float) -> void:
	if is_inside == true:
		interact()

func interact():
	if Input.isactionjust_pressed("Interaction"):
		print("Interagie")


func onPortebodyentered(body):
	is_inside = true

func onPortebodyexited(body: Node) -> void:
	is_inside = false

THX A LOT ! My Friend.

AllanOnAir | 2020-07-31 00:11