0 votes

onready var Yaw = get_parent()


func ready():

func lookupdownrotation(rotation = 0):
var toReturn = self.get_rotation() + Vector3(rotation, 0, 0)
toReturn.x = clamp(toReturn.x, PI / -2, PI / 2)
return toReturn

func lookleftrightrotation(rotation = 0):
return Yaw.get_rotation() + Vector3(0, rotation, 0)

func mouse(event):
Yaw.setrotation(lookleftrightrotation(event.relative.x / -CAMERATURNSPEED))
rotation(lookupdownrotation(event.relative.y / -CAMERATURNSPEED))

func _input(event):
if event is InputEventMouseMotion:
return mouse(event)

in Engine by (58 points)

1 Answer

+2 votes

Change InputEventMouseMotion to InputEventJoypadMotion
Change event.relative.x and event.relative.y to axis_value
Change JOY_AXIS_0 and JOY_AXIS_1 to the ones you want to use

func mouse(event):
    if event.axis == JOY_AXIS_0:
        Yaw.setrotation(lookleftrightrotation(axis_value / -CAMERATURNSPEED))
    if event.axis == JOY_AXIS_1:
        self.setrotation(lookupdownrotation(axis_value / -CAMERATURNSPEED))

func _input(event):
    if event is InputEventJoypadMotion:
        return mouse(event)
by (5,840 points)
edited by
if event.axis == JOY_AXIS_2:
    Yaw.set_rotation(look_leftright_rotation(axis_value / -CAMERA_TURN_SPEED))
if event.axis == JOY_AXIS_3:
    self.set_rotation(look_leftright_rotation(axis_value / -CAMERA_TURN_SPEED))

it just spins round weirdlt fast even without touching the sticks

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 Frequently asked questions and 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 [email protected] with your username.