0 votes

So guys, i just finished a "Your first game" from godot tutorials,and i exported that game to Android,so bassicaly game works on android fine,but problem with game "Dodge The Creeps" is that i just can't move my character cause i guess it's script isn't designed for that,on pc it works well with arrow keys,but what about Android what should i do and can i find somewhere more about it?

in Engine by (25 points)

1 Answer

0 votes
Best answer
extends Node2D

var direction = Vector2(0.0, 0.0)
var speed = 100

onready var player = $character

func _input(event):
    if event is InputEventScreenTouch:
        if event.is_pressed():
            direction = player.to_local(event.position).normalized()
        else:
            direction = Vector2(0.0, 0.0)
    elif event is InputEventScreenDrag:
        direction = player.to_local(event.position).normalized()

func _process(delta):
    position = position + direction * speed * delta

you just need to map the direction to left/right/up/down, or add button to control direction;

by (67 points)
selected by
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.