I've been working on a Tenchu-style stealth system, and I've run into a problem.
I use Unity, and asked over there, but I'm not getting a solution.
My problem is when the player presses their back against a wall, in this case a cube. I can only get the player to face (away) parallel with one side of the cube, by using the camera, on the other sides, I can't figure out how to do it.
Has anyone here a solution please?
var dir = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, dir * distanceToWall, Color.blue);
if (Physics.Raycast(transform.position, dir, out hit, distanceToWall))
{
if (hit.collider.gameObject.tag == "Sneaking Volumes")
{
if (animation.IsPlaying("P1TurnAgainstWall"))
{
animation.CrossFade("P1WallHideStand", 1.0f);
TPController.characterController.Move(-hit.normal);
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x,
Mathf.Lerp(transform.rotation.eulerAngles.y,
Camera.mainCamera.transform.eulerAngles.y,
.5f),
transform.rotation.eulerAngles.z);
TPController.characterController.radius = .3f;
}
}
}