- Home /
raycast animated suspension
i am using a raycast directed downwards along an objects local y axis, at the raycast.hit location, i am placing my wheel. i had already had this working on a previous vehicle. and it worked exactly as it should. needed to reverse the axis, so i just used -raycst.hit.distance and it worked. added a variable to correct for wheel displacement and no problems there either. but now. all i get is extremely wierd behaviour from the wheel. and any corrective value implement just makes it worse. i did a testof the values by positioning the wheels x tranform, and subtracting it by a corrective value.and no errors or unexpected behavoiur occured. please help me understand what i am doing wrong.ive spent 5 hours on it.nd nothing has worked. i willpost my code below
pragma strict
ar wheel :Transform; var poscorr = 3.0; function Update(){ var hit :RaycastHit; if (Physics.Raycast (transform.position, -Vector3.up, hit, 20.0)) { var distanceToGround = hit.distance; print(distanceToGround); wheel.localPosition.y = -distanceToGround + poscorr; } //x position includng corrective variable wheel.localPosition.x = -5.0 -poscorr; } btw...... it seems subtracting distanceToGround and adding the poscorr variable has fixed the issue. feel free to toy with script. im off to implement it...now that it works,mostly :)
im new to this, so sorry if my i put my code into the question wrong
if the wheel object is directly beneath the raycast origin i get huge up and down motions,but if i offset along the xdirection, the problems resolves and the animation works properly again