Top Down Camera Forward Axis and Right Stick

Hm, yes I think I see what you mean now. I don't have a gamepad to test with right now, but I wonder if you could just modify direction based on the camera's current angle? E.g. if the camera is rotating about the Y axis, then you should be able to just add the camera's rotation to direction, something like direction += m_Camera.transform.eulerAngles.
Hi Andrew, sorry I've only just had a chance to attempt this, but not having any luck.

I'm not quite sure how to 'place' that code, have tried the following:

// If the mouse hasn't moved then get the axis to determine a look rotation. This will be used for controllers and virtual input.
var direction = Vector3.zero;
direction += m_Camera.transform.eulerAngles;
direction.x = m_PlayerInput.GetAxis(m_PlayerInput.HorizontalLookInputName) + m_Camera.transform.eulerAngles.x;
direction.z = m_PlayerInput.GetAxis(m_PlayerInput.VerticalLookInputName) + m_Camera.transform.eulerAngles.z;

ALSO TRIED

// If the mouse hasn't moved then get the axis to determine a look rotation. This will be used for controllers and virtual input.
var direction = Vector3.zero;
direction.x = m_PlayerInput.GetAxis(m_PlayerInput.HorizontalLookInputName) + m_Camera.transform.eulerAngles.x;
direction.z = m_PlayerInput.GetAxis(m_PlayerInput.VerticalLookInputName) + m_Camera.transform.eulerAngles.z;


The result is the ANY right stick input makes Character face one direction only. I'm completely unsure how to use the line you suggested, whether it should replace something or where to place it!
 
Hm, yes I think I see what you mean now. I don't have a gamepad to test with right now, but I wonder if you could just modify direction based on the camera's current angle? E.g. if the camera is rotating about the Y axis, then you should be able to just add the camera's rotation to direction, something like direction += m_Camera.transform.eulerAngles.
Ok actually I did notice something, tried again and had a more progressive result.

So with this:
// If the mouse hasn't moved then get the axis to determine a look rotation. This will be used for controllers and virtual input.
var direction = Vector3.zero;
direction += m_Camera.transform.eulerAngles;
direction.x = m_PlayerInput.GetAxis(m_PlayerInput.HorizontalLookInputName);
direction.z = m_PlayerInput.GetAxis(m_PlayerInput.VerticalLookInputName);

I'm testing 4 compass directions using 'Forward Axis' to rotate the camera to essentially 0,90,-90, 180 degrees.

At 0 degrees, RStick controls are normal as expected.

At +or- 90, the RStick controls are 90 degrees out in the corresponding(or perhaps inverted corresponding) direction

At 180 degrees they're completely reversed.

So this is some sort of progress, but still not quite sure where to head to get it all normalised.....
 
You may want to read up a bit on how to rotate vectors and quaternions. In this case you've got direction, a Vector3, defining the direction of the character's rotation. You can rotate a vector by a quaternion by simply multiplying them (the quaternion must be on the left-hand side of the operation), so you'd need to use the camera's rotation, not eulerAngles as I initially suggested.

So you'd simply need to do direction = m_CameraTransform.rotation * direction; - this would need to come after the direction's X and Z values get set to the player's input, i.e. first it gets the player's input, then rotates that vector by the camera's rotation.
 
Top