Help, how to rotate the local Y axis of a Configurable joint while moving forward

Hi,

I am able to move vehicle forward by using the following code, however, I am not able to do any rotation on the front wheels. I tried to set target rotation, setting limit rotation along y-local axis and nothing works. Could someone please give me a pointer how this should be done?

I set both target rotation to 35 in the inspector, but it won’t budge.

function FixedUpdate() {
	var axisVertPos : float = Input.GetAxis("Vertical");
	var axisHorizontal : float = Input.GetAxis("Horizontal");
	
	
	frontLeftWheel.targetRotation.y = axisHorizontal * turning;
	frontRightWheel.targetRotation.y = axisHorizontal * turning;
	
	frontLeftWheel.targetAngularVelocity = Vector3(axisVertPos * maxAngularVelocity, 0, 0);
	frontRightWheel.targetAngularVelocity = Vector3(axisVertPos * maxAngularVelocity, 0, 0);
	rearLeftWheel.targetAngularVelocity = Vector3(axisVertPos * maxAngularVelocity, 0,0);
	rearRightWheel.targetAngularVelocity = Vector3(axisVertPos * maxAngularVelocity, 0,0);
	
	//Debug.Log(rearRightWheel.targetAngularVelocity.x + " " + frontRightWheelTransform.transform.eulerAngles.y + " " + frontRightWheel.targetRotation.y);
}

ConfigurableJoint.targetRotation is a Quaternion not an Euler, so setting the y axis like that is wrong. Using the ConfigurableJoint to create a wheel is a bad idea in the first place, why don’t you just use a WheelCollider?

if you want targetRotation to have any effect, you will have to set Position Spring in Slerp Drive to greater than 0. But in this case it will just conflict with targetAngularVelocity and make your wheel wobble. Thats because targetAngularVelocity is trying to achieve a certain angular velocity, but targetRotation is trying to keep it fixed at another rotation…

So as I said, try WheelColliders :wink:

Hi Partel,

Thanks for your reply. I did try WheelCollider. But my terrain is bumpy and if the wheelCollider does not land vertically on the rock, then my wheel and the entire vehicle will sink into the ground, please see this post. I am happy with wheel collider properties for smooth terrain.

That’s why I tried t use sphere collider instead. Do you have other suggestion?

Regards,
ikel