#Making a simple 3d player/controls
1 messages · Page 1 of 1 (latest)
Basically read inputs with _unhandled_input() or _input() and store any mouse movements.
Then during _process()
Apply those movements as rotation.
var camera: Camera3D = $CameraNodePath
var mouse_move: Vector2
func _input(event: InputEvent):
if event is InputEventMouseMotion:
mouse_move += event.relative
func _process(delta: float):
var rotation_to_apply: Vector3 = Vector3(mouse_move.y, mouse_move.x, 0)
camera.rotation += rotation_to_apply
#Reset the stored movements so far since they have been applied.
mouse_move = Vector3.ZERO
Vector3 has an X, Y and Z axis in that order.
X is up and down tilt. Y is the left and right spin.
You can think of the axis as a skewer, so Y being the vertical axis, is like a standing pole.
oh damn
I decided to copy and paste it into my project to see if it'll work, and got a parser error for the if event is InputEventMouseMotion:
You used tab for indentation on line 7 and spaces everywhere else
dose indents and spaces different enough?
What?
You can’t mix tabs and spaces for indentation like the error says
You have to pick one and stick with it
I see I see
getting a "the defualt string is using "$" which wont return nodes in scene tree before "_ready()" is called. Use the "@OnReady" annotation to solve this"
Do what the error says
Annotate that line as @onready
Errors are your friend not your enemy, they often tell you exactly what’s wrong, sometimes even how to fix it
I see, I didn't know it was as simple as it read, now getting a "cameranodepath" not found
actually let me screen shot it again
Ah wait, I didn’t actually read the line properly, that whole line is entirely unnecessary
The script is the camera node
No need to get it
Then line 15 instead of camera.rotation just rotation (or self.rotation, the self is implicit but some people prefer the explicit style of writing self.rotation)