- Home /
Question by
JuanseCoello · Apr 02, 2014 at 01:40 AM ·
rigidbodyraycastcolliderhit
How to limit a ray to go downwards to infinity, how can I make it down only 1 float.
I have a character with a rigidbody, that casts a ray downwards, I want the ray to go downwards just one unit. This is the code.
using UnityEngine; using System.Collections;
public class TP_Controller : MonoBehaviour { public static Rigidbody Rigidbody2; public static TP_Controller Instance;
RaycastHit hit;
float dist;
Vector3 dir;
public bool isgrounded;
void Awake () // Debe quedarse en awake
{
Rigidbody2 = GetComponent("Rigidbody") as Rigidbody;
Instance = this;
}
void Update ()
{
if (Camera.mainCamera == null)
return;
GetLocomotionInput();
TP_Motor.Instance.UpdateMotor();
dist = 10;
dir = new Vector3(0,-1,0);
Debug.DrawRay(transform.position, dir * dist, Color.green);
}
void IsGrounded()
{
if(Physics.Raycast(Rigidbody2.transform.position, dir, out hit, dist)) // This must be edited
{
isgrounded = false; // Debe mantenerse en true
}
}
Comment