I have a character (Sonic) so I wanted him to walk while being to be parallel to the geometry level :
but now it’s :
I use third person controller with rigidbody and capsule collider.
I have tried to use Locomotion System : Unity Asset Store - The Best Assets for Game Making; but it dont work on Unity 5. I know an asset who can do that but it’s paid(PGDK) : Unity Asset Store - The Best Assets for Game Making
I hope you can help me.
Thanks
Cherno
2
public LayerMask terrainLayer;
public bool grounded = false;
private Quaternion rotCur;
private Vector3 posCur;
void Update() {
Ray ray = new Ray(transform.position, -transform.up);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 1f, terrainLayer) == true) {
rotCur = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
posCur = new Vector3(transform.position.x, hit.point.y, transform.position.z);
grounded = true;
}
else {
grounded = false;
}
if(grounded == true) {
transform.position = Vector3.Lerp(transform.position, posCur, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, rotCur, Time.deltaTime * 5);
}
else {
transform.position = Vector3.Lerp(transform.position, transform.position - Vector3.up * 1f, Time.deltaTime * 5);
if(transform.rotation.eulerAngles.x > 15) {
turnVector.x -= Time.deltaTime * 1000;
}
else if(transform.rotation.eulerAngles.x < 15) {
turnVector.x += Time.deltaTime * 1000;
}
rotCur.eulerAngles = Vector3.zero;
transform.rotation = Quaternion.Lerp(transform.rotation, rotCur, Time.deltaTime);
}
}