- Home /
Problem is not reproducible or outdated
Moving Character Along Round Tunnel Walls
What I'm trying to achieve is to align and move character inside a (arbitrary shaped, yet round, twisting and maybe looping) tunnel shape with "feet" always touching the ground. Physics and path following are not options for me, so I started with basic raycast solution:
void Update()
{
RaycastHit rcHit;
Vector3 theRay = transform.TransformDirection(-Vector3.up);
if (Physics.Raycast(transform.position, theRay, out rcHit))
{
float groundDis = rcHit.distance;
transform.rotation = Quaternion.FromToRotation(Vector3.up,rcHit.normal);
float movement = Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime;
transform.localPosition =
new Vector3(transform.localPosition.x + movement, (transform.localPosition.y - groundDis)+.2f, transform.localPosition.z);
}
}
However the result is not what I expected. At first everything goes smoothly but when character has moved enough to left/right so that he's standing in angle of >90 degrees sideways he starts going through the tunnel wall, eventually going through the wall and preventing raycast from hitting the wall.
What am I missing here? Does someone have a better way of doing this?
Follow this Question
Related Questions
Align plane to normal but keep Y-axis intact 1 Answer
Use OnTriggerEnter during a transform ! 0 Answers
Raycast when swipe or touchphase move 0 Answers
Kart Racer - Align Kart to hit.normal on X and Z, but not Y 0 Answers
Why is this Raycast not working ? 3 Answers