#Making a simple 3d player/controls

1 messages · Page 1 of 1 (latest)

proud fossil
#

I wanted to make basic 3d movment, camera, and physics, but idk where to really start?

I wanted to start with camera movement but I can't seem to find anything and I didn't wanna follow a guide beat for beat.

rancid onyx
#

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.

proud fossil
#

oh damn

proud fossil
#

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:

short socket
proud fossil
short socket
#

You can’t mix tabs and spaces for indentation like the error says

#

You have to pick one and stick with it

proud fossil
#

I see I see

proud fossil
#

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"

short socket
#

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

proud fossil
#

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

short socket
# proud fossil

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)

proud fossil
#

Im now getting a "Invalid operands 'Vector3' and 'Vector2' in operator '+'

#

from what I read its grabbing from two seperate Vectors that can't attach to each other?

rancid onyx
#

mouse_move is a Vector3, but mouse movement only happens in 2D space.

#

Keep in mind my example above also makes mouse_move a Vector2