A way to raycast ahead and down?

I have a world set up where a trench runs through part of it where my character isn’t allowed to go. The way the meshes were set up don’t really allow me to use collisions because a collision doesn’t occur until my character falls into the trench ( which I don’t want to happen). Is there a way I can raycast ahead and DOWN to look for collisions ahead of time? I see Vector3 has a .up variable but not a .down one. Oh, would Vector3(0, -1, 0) be down?

-Vector3.up is the usual way to say ‘down’. There used to be a Vector3.down, but it was removed to keep the API streamlined. This may have indirectly been my fault. :wink:

You might find it preferable to have a big invisible trigger collider hovering over your trench. You could then raycast against it to see if you’re too close to it, but things would still be able to fall into the trench if necessary. You could also use a non-trigger collider as a simple invisible wall.

Finally, a good trick is to have the invisible trigger collider act as a force field which pushes you back if you try to enter it. That helps to avoid the whole invisible wall thing (which is something I particularly hate in games).

Yes, Vector3(0, -1, 0) is down (so is -Vector3.up). Just raycast using those two vectors.

Thanks guys. I was hoping to use Raycasting instead of an invisible collider as it’s a pretty big trench that contours quite a bit. If I had more time I would have the artist do the meshes over.

Thanks a lot, Neil! :roll: (Actually, it’s not a big deal…)

Anyway, you can raycast in any direction; just put that direction in the Vector3. Ahead and down would be (0, -1, 1)…if that needs to be normalized, then you can do

var someVector = Vector3.Normalize(Vector3(0, -1, 1));

–Eric

So, it’s Neil’s fault I had to change all that old code.

Just watch your back, Carter.

Well, you still can raycast if you wish to… Unity - Scripting API: Physics.Raycast

I totally did it to trip you guys up. :wink:

Actually, I put in a feature request for transform.forward and friends to be added as a convenient shorthand for transform.rotation * Vector3.forward etc. This was subsequently implemented, but only for .forward, .up and .right. When I mentioned this, instead of adding the missing directions, they were removed from Vector3 as well! As I described above, this was done because it was felt that the API had become too redundant and needed streamlining a bit.

Anyway, if there are any other features that you don’t want any more, drop me a line and I’ll put together another feature request. :smile:

Hey, Neil.

Ask them to not fix Unity’s Undo!

And ask them to not do it before the end of the year!!

:wink: