Why isnt my raycast hitting the floor?
Rigidbody m_body;
public float m_hoverForce = 9.0f;
public float m_hoverHeight = 2.0f;
public GameObject[] m_hoverPoints;
int m_layerMask;
// Use this for initialization
void Start () {
m_body = GetComponent<Rigidbody>();
m_layerMask = 1 << LayerMask.NameToLayer("Characters");
m_layerMask = ~m_layerMask;
}
// Update is called once per frame
void FixedUpdate () {
RaycastHit hit;
for (int i = 0; i < m_hoverPoints.Length; i++)
{
var hoverPoint = m_hoverPoints [i];
if (Physics.Raycast(hoverPoint.transform.position, hoverPoint.transform.forward , out hit, m_hoverHeight, m_layerMask))
m_body.AddForceAtPosition
(hoverPoint.transform.forward * m_hoverForce * (1.0f - (hit.distance / m_hoverHeight)), hoverPoint.transform.position);
Im not the best at coding and have just started out. Im using a script i learned from a tutorial and im trying to change it so that my raycasts come out in the direction of the hover points (locally) rather than just straight down globally.
The code previously had -Vector3.up instead of hoverPoint.transform.forward, in the if statement parameters.
While debuging, I see the raycast comes out perfecly as I want it, however for some reason it is not registering a hit with the floor, however it registers the hit when I use -Vector3.up (which isnt what I want)
Does anyone know why this could be happing?
Your answer
Follow this Question
Related Questions
how to check if an object is betwen enemy and player 1 Answer
Movement Sticking 0 Answers
Display GameObjects tag using Raycast 1 Answer
How can I move an object in the direction another object is facing. 1 Answer
Searching a function to get the rotation of one Vector3 in relation to another 1 Answer