|
|
|
|
Reply From: |
Pixelope |
Just this morning I’ve been trying to figure this out, so far I have the following:
var rs_look = Vector2()
func _physics_process(_delta):
rslook()
func rslook():
rs_look.y = Input.get_joy_axis(0, JOY_AXIS_3)
rs_look.x = Input.get_joy_axis(0, JOY_AXIS_2)
rotation = rs_look.angle()
I have a variable for the right stick set to Vector 2. I then created a new function called rslook() which i call in the physics process. In the rslook() function I then add the y and x axis input (deviceID, AXIS) and then set rotation.
Note: The Udemy course I’m doing tells us to create new functions and then reference it in the physics process, I guess to keep the code organised (I’m not sure), however you can ignore the rslook() function altogether and put just the code in the physics_process like this and it works still:
var rs_look = Vector2()
func _physics_process(_delta):
rs_look.y = Input.get_joy_axis(0, JOY_AXIS_3)
rs_look.x = Input.get_joy_axis(0, JOY_AXIS_2)
rotation = rs_look.angle()
I just need to set up deadzones properly because without pressing the right stick it moves slightly, so having deadzones properly set up should resolve this…but I haven’t got that far yet. I hope this all makes sense, I too am very new to godot/gdscript.
– EDIT –
Here is the updated code with deadzone added, play around with the deadzone value, don’t forget to take into consideration ‘stick flick’, if your deadzone is too low, when you release the stick it might flick back and turn the player by accident:
var rs_look = Vector2(0,0)
var deadzone = 0.3
func _physics_process(_delta):
rslook()
func rslook():
rs_look.y = Input.get_joy_axis(0, JOY_AXIS_3)
rs_look.x = Input.get_joy_axis(0, JOY_AXIS_2)
if rs_look.length() >= deadzone:
rotation = rs_look.angle()
My player doesn’t rotate by the own axis.
How can I fix this?
Joshfah | 2021-03-09 03:23