Hi, im here again with new curious problem ![]()
I have some car and a script, which is generating skidmarks:
using UnityEngine;
using System.Collections;
public class SkidScript : MonoBehaviour {
public GameObject skidSound;
public float currentFrictionValue;
public float skidAt = 0.1f;
public float soundEmition =15;
public GameObject skidSmoke;
public float smokeDepth = 0;
public bool rearWheel = false;
private float soundWait;
public float markWidth = 0.025f;
private int skidding;
private Vector3[] lastPos = new Vector3[2];
public Material skidMaterial;
void Start () {
skidSmoke.transform.position = transform.position;
Vector3 position = skidSmoke.transform.position;
position.y -= smokeDepth;
skidSmoke.transform.position = position;
}
// Update is called once per frame
void Update () {
WheelHit hit;
transform.GetComponent<WheelCollider>().GetGroundHit(out hit);
currentFrictionValue = Mathf.Abs(hit.sidewaysSlip);
if (skidAt <= currentFrictionValue && soundWait <= 0)
{
Instantiate(skidSound, hit.point, Quaternion.identity);
soundWait =1;
}
soundWait -= Time.deltaTime * soundEmition;
if (skidAt <= currentFrictionValue)
{
skidSmoke.particleEmitter.emit = true;
SkidMesh();
}
else
{
skidSmoke.particleEmitter.emit = false;
skidding =0;
}
}
void SkidMesh()
{
WheelHit hit;
//HERE IS THE PROBLEM:
transform.GetComponent<WheelCollider>().GetGroundHit(out hit);
Debug.Log(hit.point.ToString("F3")+" . "+transform.position.ToString("F3"));
GameObject mark = new GameObject("Mark");
MeshFilter filter = mark.AddComponent<MeshFilter>();
mark.AddComponent<MeshRenderer>();
//some code....
}
}
Problem is that position of Wheel Hit in SkidMesh function is wrong, so skid marks also have wrong position (see image)
What could i do?
I tried almost everything but i still canโt find solution
