0 votes

I am brand new to coding so I have no idea what I'm doing, I'm using GODOT 2.1.
I am trying to create a button the player can press in the game using "ui_accept" by moving over to it with an animated sprite.
This is the script for my player

extends Area2D

var screensize
export var speed = 175
var vel = Vector2()
onready var sprite = get_node("Sprite")
var anim = "walkies"

func _ready():

screensize = get_viewport_rect().size

set_pos(Vector2 (100,300))

func fixedprocess(delta):

var input = Vector2(0,0)
input.x = Input.is_action_pressed("ui_right") - Input.is_action_pressed("ui_left")
vel = input * speed
set_pos(get_pos() + vel * delta)
if vel.x != 0:
    anim = "walkies"
    anim = "idle"

if vel.x > 0:
elif vel.x < 0:
var pos = get_pos() * vel * delta

I have a button scene that can detect when the player is within range with this code (albeit the player sprite walks "behind" the button which is not ideal I would like to appear in front of the button) :

extends Area2D
var anim = "default"
var pos = Vector2(500,240)

func _ready():


func processinput():

func onArea2Dareaenter( area ):


How can I make it so that the player can walk into the button's range, press "uiaccept", and activate the animated sprite in the button scene? Eventually I'd like to have the button do something else but right now I just want to figure out how to get it to animate when the player is WITHIN range and then PRESSES the "uiaccept" key.

asked Dec 9, 2017 in Engine by Postendustrial (12 points)

Sounds like you have this mostly solved already. Connect a function to the areaexit as well, and you will be able to toggle a boolean when an object enters/exits the area of interest. If you have more than one object that might be triggering the signal, you need to also check the object to see if it's your player character. When you check if "uiaccept" has been pressed, check if your boolean is set, and if it is, play your animation.

P.S. If you indent all of the code in your question with four spaces, it will make it significantly more readable.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.