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
    add_child(aPlayer)

func _physics_process(delta) -> void:
    if Input.is_action_just_released("iPlayerInteract"):
        _Interact()
    else:
        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():
    pass

func _Move(vSelf, vDirection):
    #MOVE
    pass

Screenshot

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

1 Answer

0 votes
#Move
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,051 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 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 webmaster@godotengine.org with your username.