Player don't move forward with direction relative to Camera

Hi everybody :slight_smile:

I’m trying to move my character with a joystick direction , relative to the camera (Cinemachine).
I don’t know why but when I put my joystick Up, If I’m not already moving , the player is like stuck…
And when I turn left , right, down, the player move normally. After moving in other direction ( without release the joystick), the player can go forward. Then after release , If I try to go forward again, the player is stuck again…

Here my code to move :

Vector3 desiredDir = (cameratransform.forward * movementJoyL.y + cameratransform.right * movementJoyL.x).normalized;
rb.AddForce(desiredDir* moveSpeed * movementMultiplier * Time.fixedDeltaTime, ForceMode.Acceleration);

I have checked the Debug for joystick values , and when my player is stuck when I try to go forward I have good values :

MovementJoyL:(0.0, 1.0)

If someone can help me to understand what i’m doing wrong here , i’ll really appreciate :smile: !

EDIT: The problem don’t came from the joystick , if I’m moving without be relative to the Camera, everything work perfectly…

Have a good day! :slight_smile:

Hey, I’m also making a game using a joystick, but I think the way I did for movement is different to yours, I used a joystick asset for now, did you make your own, or used an asset as well?
I used this one (https://assetstore.unity.com/packages/tools/input-management/joystick-pack-107631) I find this one really easy to use for movement, by using attributed like Joystick.direction or Joystick.vertical, Joystick.Horizontal , Using these makes it easy to implement things like player movement etc.
I’m not telling you to change or anything, just to check it out. And sorry I couldn’t help with your question :frowning:

1 Like

Hi @Johan_Liebert123 :)!

For the joystick i’m using the included one : “OnScreenStick”

But i’m 100% sure that it don’t came frome the joystick. the debug value return good values…
the problem came from “cameratransform.forward * movementJoyL.y + cameratransform.right * movementJoyL.x”

When i’m using a simple movement function without to be relative to camera everything work perfectly :rage:

Thanks for helping me :smile:

Basically you need to use the heading of the camera to rotate the inputs.

This is a script out of a fully-functioning project you can download at this location:

https://github.com/kurtdekker/proxi…edControls/RotatedControlsPlayerController.cs

Notable lines above:

Line 124 - get the camera heading

Line 126 - construct a rotation

Line 128 - produce the rotated controls from the unrotated controls

Line 130 - use them

1 Like

Thanks to you !! It’s working like a charm :smile: :smile:

1 Like