Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Raycast Issue

$
0
0
Ok I asked this last night but didn't give enough information, so here goes. I use this code to make a gameobject kinematic when it is a certain distance from an object. it works fine but there is a small difference between the positions it stops at, 0.4 to be precise. private var speed : float = 2000; private var Range : float = 3.7; private var DirectionRay : Vector3; function Awake(){ rigidbody.isKinematic = true; } function Update () { if(rigidbody.isKinematic){ if(Input.GetKeyUp("up")){ rigidbody.isKinematic = false; DirectionRay = Vector3.up; rigidbody.AddForce(Vector3.up * speed); } if(Input.GetKeyUp("down")){ rigidbody.isKinematic = false; DirectionRay = Vector3.down; rigidbody.AddForce(Vector3.down * speed); } } } function FixedUpdate(){ var wall : RaycastHit; Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue); if(Physics.Raycast(transform.position, DirectionRay, wall, Range)){ if(wall.collider.gameObject.tag == "bound" && !rigidbody.isKinematic){ rigidbody.isKinematic = true; } } } I took a picture of the Debug Raycast and you can clearly see that the raycast goes into the gameObject at different lengths! Strange or am I missing something obvious? ![alt text][1] ![alt text][2] [1]: /storage/temp/11342-raycast_pic1.png [2]: /storage/temp/11343-raycast_pic2.png

Viewing all articles
Browse latest Browse all 171066

Trending Articles