Turn a Centipede while moving forwards using isKinematic

Hello,

I’ve got a small personal project I’m currently working on: it’s sorta like centipede from the days of yore.

I’m having some trouble getting my enemy Centipede to turn. I’ve got a box collider that is supposed to cause him to turn to the right 180 degrees while moving forward.

The centipede is a rigidbody with gravity turned off. When he touches the collider, I enable isKinematic and have been struggling to rotate him naturally.

I’ve tried about 3 different ways now, to no avail.

I’m using the following methods:

void TurnRight()
{

	//transform.rotation = Quaternion.Slerp(from.rotation, to.rotation, Time.time * turnMultiplier);
	//transform.RotateAround(Vector3.right, turnDirection, 10 * Time.deltaTime);
	//transform.Rotate(Vector3.right * turnMultiplier * Time.deltaTime);
}

void OnTriggerStay(Collider other)

{
rigidbody.isKinematic = true;
TurnRight();
}

I’m definitely in over my head, so any advice would be greatly appreciated.

Thanks in advance!

Well, as long as you don’t mind the rotation going to a specific angle in 2 sec, try this:

transform.rotation = Quaternion.AngleAxis(Mathf.Lerp(0,180,Time.time/ 2), Vector3.up);

Thanks! I went ahead and pasted/tested that line, and it seems to be responding… strangely.

As soon as it touches the collider, it freaks out and instantly appears about 2 meters away facing straight down into the floor plane.

Am I using the right Trigger method? Should I use OnTriggerEnter instead? Should I be using isKinematic? I disabled it for the test and it didn’t seem to alter anything, but I drive the Centipede with it’s rigidbody normally, and the switch to Kinematic doesn’t seem to be helping anything.

Thanks again!

-Fred

Excellent. It moves in the right direction, although the attached objects are really jittery, I may be able to work around it.

What do you think of using a wheel collider in this situation? Would that let me turn it more naturally?

Thanks again.