hai everyone...iam new to unity...am trying to move a car in a terrain surface(mountain).using raycast.hit function i get my car up when am hitting in the mountain surface..but my car doesnt gets down...the position of the car cannot be rest to terrain i,e ground....here is my code...Thanks...
car moving script..
public float movespeed=300;
public float turningSpeed=40;
start(){}
void update(){
float horizontal=Input.GetAxis("Horizontal")*turningSpeed*time.deltaTime;
transform.rotate(0,horizontal,0);
rigidbody.addforce(input.getaxis("Vertical")*movespeed*transform.right)
}
this is my raycast codings...
public class finddistance
{
public Transform target;
void start(){}
void FixedUpdate(){
RaycastHit hit;
if(physics.Raycast(transform.position,-vector3.down,out hit)){
float distanceGround=hit.distance;
float heightToAdd=transform.localScale.y;
target.Translate(0,transform.position.y-distanceGround+heightToAdd,0);
}
}
pls ignore the cases of the letters....and i dont have any colliders in my project.
↧