Raycast on moving object?
My problem is that I have a rocket moving forward (transform.translate.forward * speed) and I also have a raycast in the Update function and it looks like the raycast is late for some reason.
(My Raycast)
if (Physics.Raycast(transform.position, transform.forward, out hit, 1))
{
Destroy(gameObject);
}
I tried Debug.Drawray and the ray is late and looks as if it is shooting out of the back of the rocket. If i have the rocket speed set to 0 then the ray looks fine, but the moment it starts moving it looks late.
(My Drawray)
Debug.DrawRay(transform.position, transform.forward, Color.blue, 1);
I have tried moving the transform.translate to the fixed update and have tried moving the raycast also to the fixed update etc..
Any help would be appreciated!!!!
Answer by sxnorthrop · Sep 25, 2016 at 10:56 PM
Did you ever figure this out?
I have not, it bugs me that no one knows what's wrong/isn't replying haha
Answer by Scoutas · Dec 28, 2016 at 01:00 AM
I have figured this out @kylenoll123, if you haven't done so already.
Always had this annoying little problem when creating 2D controller collisions, because my character would get stuck in walls constantly.
Basically, the length that your ray is late by, is the length that the rocket has moved in the previous frame. This makes sense?
Here, a masterfully crafted image to illustrate this:
I hope it's clear enough, took me several months to get to this simple conclusion...
Your answer
Follow this Question
Related Questions
Raycasting Stopped Working all of a sudden 0 Answers
2D collision trouble, character falling through map 1 Answer
Rotated object raycasting in wrong directions!!? 3 Answers
Add colliders to original/root asset? 1 Answer
RigidBody Collisions Detect 0 Answers