Skip to content

Instantly share code, notes, and snippets.

@WolfgangSenff
Created April 20, 2019 02:47
Show Gist options
  • Save WolfgangSenff/852160e4847afa6cd7008960b72c8f86 to your computer and use it in GitHub Desktop.
Save WolfgangSenff/852160e4847afa6cd7008960b72c8f86 to your computer and use it in GitHub Desktop.
Move in 3D space in Godot using translation
extends Spatial
var speed = 100
func _physics_process(delta):
if Input.is_action_pressed("ui_space"):
translation += speed * (Vector3.RIGHT.rotated(Vector3(0, 1, 0), rotation.y)) * delta
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
var mouse_pos = get_viewport().get_mouse_position()
rotation.y = -(mouse_pos - $Camera.unproject_position(translation)).normalized().angle()
@Title-Pending
Copy link

Thank you.

@Title-Pending
Copy link

Title-Pending commented Apr 20, 2019

I learned RIGHT can be replaced with FORWARD BACK UP DOWN and LEFT thank you thank you. Strangely BACK makes the thing go forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment