Strange physics raycasting behaviour
Hi,
I have a little pooling script for a small project I am working on, when you click, the collision box is teleported away, to remove the collisions for that block, however I seem to be running into a weird raycast issue. When I teleport the block it seems like the raycast still picks up the blocks previous position.
A short GIF of the issue can be found here: http://puu.sh/qZFDP/9d7bed3859.gif
Is there another cause for this happening or is this a bug? The following code is used to raycast the point :
RaycastHit hit;
Ray r = new Ray(transform.position, transform.forward);
if (Physics.Raycast(r, out hit))
{
cursorPointer.transform.position = hit.point;
}
else
{
cursorPointer.transform.position = transform.position;
}
There isn't much you can do wrong when raycasting. Please show the object hierarchy and how you hide the block.
Did you get a chance to look at the GIF I posted? I teleport the collider to (100,100,100) just to test.
So you just change the position of the collider component? What about the object itself?
I would try to just to set the whole gameobject to non-active.
From what I understand, It hits that actual object that is teleported away, It just seems to think that it still exists in the same place. It's bizarre behaviour that I've never run into before and I want to think that it is my own issue, I just never found a way to explain it.
"From what I understand", doesn't make it sound like you're convinced. Have you actually logged its name, for example?
I'd guess the raycast is perfect, but something else, not shown here, in your code is wrong. When you move the object, there's probably a delay until you run the raycast again.
I've seen funny "takes an extra frame" issues when moving things, but never (in recent Unity's) with a raycast. I've found I can move any sort of collider in/out one line before the raycast, and it always works.
The raycast is per frame and the cube is teleported away once and pooled, no other teleporting occurs. You can see that it is per frame as it continually moves the sphere over the object