- Home /
Question by
ZWLSOFTWARE · Jun 01, 2020 at 08:39 PM ·
physicscubewheel colliders
cube on 2 wheelcolliders
Hello, does anyone know how to make a cube on 2 wheels? and keep the x lerping to 0 but also keep a leaning effect when driving.
I have made this script but this doesnt work with wheel colliders it will push the wheels forward or backwards or go crazy
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class stabalizeRobo : MonoBehaviour
{
public float x; // current x rotation
Vector3 r; //get the x rotation
Vector3 a; //vector3 zero
public float speed; //set speed of rotation
private void FixedUpdate()
{
x = transform.localEulerAngles.x;
r = new Vector3(transform.rotation.x,0,0);
a = new Vector3(0,0,0);
//math to get the x fixed value
if (x > 256f)
x = (x * -1f) + 360f;
else
x = -x;
// lerp back to zero
if ( x >= 0)
{
Debug.Log("over 0");
transform.eulerAngles -= Vector3.Lerp(r, a, 100f * -Time.deltaTime) * -speed * Time.deltaTime;
}
if( x <= 0)
{
Debug.Log("under 0");
transform.eulerAngles -= Vector3.Lerp(r, a, 100f * -Time.deltaTime) * speed * Time.deltaTime;
}
}
}
Comment
Hey @ZwolloGames,
This sounds pretty similar to a question I answered recently about leaning an object forward while moving and co$$anonymous$$g back to upright when not moving. $$anonymous$$aybe it can give you some inspiration:
https://answers.unity.com/questions/1742839/how-to-offset-an-objects-rotation-using-lerp.html
Good luck!