- Home /
how to know if transform position through hit.point ??
i create a simple script for raycast
public Vector3 velocity;
public Vector3 rayDirection;
public Color color;
public LayerMask hitLayer;
public Vector3 hitPoint
public bool hitSomething = false;
private void Awake()
{
rb = GetComponent<Rigidbody>();
color.a = 255;
}
private void FixedUpdate()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, rayDirection, out hit, Mathf.Infinity, hitLayer))
{
Debug.DrawRay(transform.position, rayDirection * hit.distance, color);
hitPoint = hit.point;
hitSomething = true;
}
else
{
Debug.DrawRay(transform.position, rayDirection * 5000, Color.white);
hitSomething = false;
}
}
but how can i know if transform through or past latest hit point ?? thanks,,
I didn't understand what you're asking. Could you please rephrase that?
Answer by DanielLichtenstern · Mar 30, 2020 at 11:42 AM
To get the transform of the object you hit, you can use "hit.transform" on the hit object itself like this:
RaycastHit hit;
if (Physics.Raycast(transform.position, rayDirection, out hit, Mathf.Infinity, hitLayer))
{
[...]
var hitObjectTransform = hit.transform;
[...]
}
The hit.point is of type Vector3 and so it doesn't contain any data beside the x,y,z coordinates.
Your answer
Follow this Question
Related Questions
Why is my cursor not moving with the updating position of the raycast hit point? 0 Answers
Getting raycast to fire at touch position but only when second finger is on screen 0 Answers
Check if player object is right above this object 1 Answer
Raycasting how to find position on end of ray float distance 1 Answer
Spawning object by using ray 1 Answer