Topic was automatically imported from the old Question2Answer platform.
Asked By
FellowGamedev
I got it mostly working but as you can see since the parent is responsible for X axis rotation and since its not moving with the ship, the ship will only rotate around the parent and not itself. And I need it to rotate around itself.
Tree: Parent(X axis rotation)
→ Child(Y axis rotation + forward and back movement)
->->Ship OBJ
I believe the potential fix for this is to either make the parent copy the child’s position (but I cant get it to work for some reason) or make one on them do both rotations. #Attached To Parent
func _input(event):
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
child.rotate_x(deg2rad(event.relative.y * MOUSE_SENSITIVITY *-1))
self.rotate_y(deg2rad(event.relative.x * MOUSE_SENSITIVITY * -1))
#Attached To Child
var speed = 0
func _physics_process(delta):
if Input.is_key_pressed(KEY_E):
speed = speed + .1
if Input.is_key_pressed(KEY_Q):
speed = speed - .1
translate(Vector3(0,0,delta*speed))
If you have another way of doing this movement I would very much appreciate if you could help me!
Aight so it turns out I was dumb and I didn’t know basis is a thing… im posting my code here incase anyone else will ever need this =) the code is basically a free float camera/node only missing z rotation
extends KinematicBody
var rot_x = 0
var rot_y = 0
var velocity = Vector3()
var speed = 1
var frictionspeed = 0.05
var MOUSE_SENSITIVITY = 0.005
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta):
velocity.x = lerp(velocity.x , 0 , frictionspeed)
velocity.y = lerp(velocity.y , 0 , frictionspeed)
velocity.z = lerp(velocity.z , 0 , frictionspeed)
if Input.is_key_pressed(KEY_W):
velocity += -transform.basis.z * speed
if Input.is_key_pressed(KEY_S):
velocity += transform.basis.z * speed
if Input.is_key_pressed(KEY_A):
velocity += -transform.basis.x * speed
if Input.is_key_pressed(KEY_D):
velocity += transform.basis.x * speed
if Input.is_key_pressed(KEY_SPACE):
velocity += transform.basis.y * speed
if Input.is_key_pressed(KEY_CONTROL):
velocity += -transform.basis.y * speed
velocity = move_and_slide(velocity)
if Input.is_action_just_pressed("ui_cancel"):
if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func _input(event):
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
rot_x -= (event.relative.x * MOUSE_SENSITIVITY)
rot_y -= (event.relative.y * MOUSE_SENSITIVITY)
transform.basis = Basis()
rotate_object_local(Vector3(0, 1, 0), rot_x)
rotate_object_local(Vector3(1, 0, 0), rot_y)
`