0 votes

Script is attached to a Tilemap for an instanced level. Not sure if the image helps. I have a player scene that gets instanced. I'm looking for the best way, after input is calculated here, to move the instanced player (aPlayer) using moveandcollide.

extends TileMap

onready var aPlayer = preload("res://Scenes/Player.tscn").instance()

var cSpawn1 = Vector2.ZERO

func _ready() -> void:
    aPlayer.position = cSpawn1

func _physics_process(delta) -> void:
    if Input.is_action_just_released("iPlayerInteract"):
        var vInputDirection = Vector2(Input.get_action_strength("iPlayerRight") - Input.get_action_strength("iPlayerLeft"), Input.get_action_strength("iPlayerDown") - Input.get_action_strength("iPlayerUp"))
        if vInputDirection != Vector2.ZERO:
            _Move(aPlayer, vInputDirection)

func _Interact():

func _Move(vSelf, vDirection):


Godot version 3.3.stable
in Engine by (12 points)

1 Answer

0 votes
vSelf.move_and_collide(vector2(0,200) * vDirection * delta)

The vector is for velocity forward (I assume your forward is +x) .
You can change it to suit your needs. Also your player has to be a kinematic body or other body with move and collide method and you also have to pass delta to the _Move method.

by (1,127 points)
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.