Hi,
I got a Camera with a MouseOrbit-Script attached, and a Character with a absic controll script,
i need help with making my character move relative to the camera, so if he moves forward he walks away from the camera and if he walks back he moves towards it. Even if i turn the camera. So that i would walk a full circle around an objct that i am locked on just by going left or right.
In the end it should behave like in Skyrim that i can controll the mouse and the player seperately but in relation to each other.
So i prepared some code to choose which direction he should face determined on which key is pressed, and the unity basic move script:
if(Input.GetKey ("w") || Input.GetKey ("a") || Input.GetKey ("s") || Input.GetKey ("d"))
{
_characterState = CharacterState.Walking;
if (Input.GetKey ("w"))
{
//go forward
} else if (Input.GetKey ("s"))
{
//go backward
} else if (Input.GetKey ("d"))
{
//go right
}else if (Input.GetKey ("a"))
{
//go left
}
}
if (_characterController.isGrounded)
{
moveDirection = new Vector3(-Input.GetAxis("Horizontal"),0,-Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
if(_characterState == CharacterState.Walking)
{
moveDirection *= walkSpeed;
}else if(_characterState == CharacterState.Running)
{
moveDirection *= runSpeed;
}
if(Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
_characterController.Move (moveDirection * Time.deltaTime);
I tried to put the movement in a method so i could acces it if the pressed key was determined and send the information which direction it should go this way, but this somehow interfered with my animations and i don’t know why because it just checks which animation is active right now and thats it… or it was messing with my CharacterStates… somehow…
Thanks in advance :3
PS: Sry for my probably bad english ^^"
As requested here are some Screenshots, even if ther isn’t much to show: