Quantcast
Channel: Latest Questions by gopics
Viewing all articles
Browse latest Browse all 48

using Raycast.hit function my car gets up and doesnt gets down ? it is in flying state

$
0
0
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.

Viewing all articles
Browse latest Browse all 48

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>