- Home /
Question by
arshiyan · Jul 27, 2011 at 07:24 PM ·
positioncarwheel-collidersuspensiondistance
problem wheel position
i use this code for wheels,
using UnityEngine;
using System.Collections;
public class wheel : MonoBehaviour {
public WheelCollider _wheel;
public GameObject smoke;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
_wheel.suspensionDistance=1.0f;
RaycastHit hit;
Vector3 colliderCenterPoint=_wheel.transform.TransformPoint(_wheel.center);
if(Physics.Raycast(_wheel.transform.position,-_wheel.transform.up, out hit,_wheel.suspensionDistance+_wheel.radius))
{
transform.position = hit.point + (_wheel.transform.up * _wheel.radius);
Debug.DrawLine(_wheel.transform.position,transform.position, Color.green);
}
else
{
transform.position = colliderCenterPoint - (_wheel.transform.up * _wheel.suspensionDistance);
Debug.DrawLine(_wheel.transform.position,transform.position, Color.red);
}
WheelHit wh;
_wheel.GetGroundHit(out wh);
if(Mathf.Abs(wh.sidewaysSlip ) > 2.0 )
{
Instantiate(smoke,wh.point,Quaternion.identity);
}
}
}
but it doesn't work when wheel touches ground,look at this image
at part of 2 means when car touches ground, position of all wheels are center of wheels, why?
_wheel.suspensionDistance=1.0f;
Comment
Best Answer
Answer by arshiyan · Jul 27, 2011 at 08:01 PM
thanks, i found my mistake
if(Physics.Raycast(colliderCenterPoint,-_wheel.transform.up, out hit,_wheel.suspensionDistance+_wheel.radius))
Your answer
Follow this Question
Related Questions
Car not turning on plane. 1 Answer
vehicle decceleration and angle reseting 1 Answer
Making a race car positioning system 5 Answers
Camera rotation around player while following. 6 Answers
Car's position indicator or Standings . 2 Answers