Using Raycast, but only for a single point

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PepijnWe

I’m using the raycast function to check for collisions.
But i want it to only check the point and not the ray. Because it needs to be able to hop over blocks.

I hope the question is clear.


It’s not clear to me what you’re trying to accomplish. I don’t see how “checking a point” will allow you to hop over blocks. By “point” I assume you mean the end of the ray, but based on your character’s position relative to a box, that still seems problematic.

You probably need to provide some additional information to get any useful assistance. Is this 2D or 3D? Maybe a picture and/or better description of the problem you’re trying to solve.

A few ideas based on limited information:

  • You can make the ray very short, and move it to what would be the “end” of a normal ray (though, again, I’m not sure what that solves)
  • You can define the array to ignore certain objects, layers, or types. Perhaps this could be used to ignore the boxes (if that’s the issue here)
  • You can simply ignore a given reported collision(or class of collisions) if you’re not interested in it.

If the above isn’t helpful, please provide additional details.

jgodfrey | 2020-09-11 17:10

Using a array to ignore certain objects would not work.
Im trying to get this move done:

Pasteboard - Uploaded Image

The red line is the line it flips over (this time the vertical one)
the yellow lines are the raycasts.
The thing is the end position is not blocked, while the path is blocked (bottom yellow line intercecting with the block)

Currently the move is not allowed because of the collision ray, but the goal is to be able to make this move.

PepijnWe | 2020-09-11 17:33

:bust_in_silhouette: Reply From: jgodfrey

Based on the above conversation, this seems to be some sort of grid-based game, right? If that’s the case, Raycasts may be more complex than necessary here. Instead, I’d probably keep an internal representation of the game grid (a simple 2D array would be fine - maybe you already have one?) and write code that determines valid “moves” based on a “start” and “end” cell.

If I understand your drawing and description, it seems that you’re just trying to determine if the “mirrored position” of a given cell is empty or not. So, in your drawing, for the square that’s 3 cells to the right of the vertical red line, you just want to know if the cell 3 cells to the left of the line is empty. That’d be really easy to do via processing a simple 2D array representing the current state of the game grid.

Thank you for this idea, i have been trying so many methods but didn’t think of this one.
Now its time to recode the whole movement again :P.
But the hardest part (mirroring) is done so it will be fine

PepijnWe | 2020-09-11 18:54