Player misaligns from ground while following camera forward
Hi everyone, i've been having this issue since i started this project. Long story short, the movement of the character that is relative to the camera; the way my character moves is meant to act as a Sonic game movement replica, more like Sonic Unleashed, the issue i'm having is that the player, everytime that the camera slowly moves or isn't in the same rotation with the player, the player will try to point in the direction of the camera forward whenever it can, i've made a image picturing how the issue interfers with the alignment:
What I wanna achieve is make the player being able to move without trying to go to the camera's forward direction so that collision can be precise. If it helps, here's the code that makes the player look at the camera's direction:
function RotatePlayer(Horizontal : float ,Vertical : float){
absLeftStick = Mathf.Clamp (Mathf.Abs(Vertical) + Mathf.Abs(Horizontal),0,1);
targetDirection = Vector3(Horizontal,0,Vertical);
targetDirection = Camera.main.transform.TransformDirection(targetDirection);
if (targetDirection != Vector3.zero) {
var targetRotation = Quaternion.LookRotation(targetDirection, transform.up);
}
var newRotation = Quaternion.Lerp(transform.rotation, targetRotation, turningSpeed * Time.deltaTime);
if(absLeftStick > 0.2f) {
transform.rotation = newRotation;
}
}
If I forgot any detail on explaining this, please tell me and I'll explain as much as I can.
Any help on this case is highly appreciated! Thanks for reading!
Answer by chaos456 · Mar 17, 2016 at 04:25 PM
Ok I actually fixed my own problem, I just had to move my movement void to fixedupdate!
Answer by gorbit99 · Feb 13, 2016 at 12:59 PM
I'm assuming the camera looks forward, not down a bit, so when setting the rotation to the camera's rotation, you basically rotate the character to look forward.
Actually, the rotation of the camera can be modified while going through hills or loop de loops, but that should be it! But I don't know of another way to set up the rotation of the player follow the direction of the camera in another way, sadlly.