Better :MoveTo() ? | Move model to nearest open area

The :MoveTo() method of models is great for teleporting a model while avoiding anything that may be obstructing the given position. The problem with MoveTo() is that it only moves the model straight up and not to the nearest open space around the position as seen here. This looks great if the position is in the ground, but not so much if the position is in a wall.

This is very useful for combat games if we need to correct a character’s position. Normally, players being up against walls or having their limbs clipping into walls is not an issue- but in combat games if you ragdoll them while their limbs are inside walls they get glitched (see below).

The issue with using MoveTo() to position the character before ragdolling them is that moving them straight up would look unrealistic in a combat game. It would be much more desirable if we could move them to the nearest open space.

I have made a prototype module that does just this (see below). However, its very unperformant as it requires a large amount of block casting or spatial queries as seen here. It would be against our interest to have the client do this since there would be latency and the server position would remain the same. Even if we did- the approach is still too costly even on the client.

I was wondering if anyone knew of any clever approach to this issue. The goal is really just to move the character to the nearest open space around a position if that position is obstructed. Thanks!

So far, the approach I’ve used works, its just horribly unperformant.

you can try raycasting from a beginning position of 100 studs or farther away from the NPC going towards to NPC’s Position from each direction (Front, Back, Left Right, Up Down), then checking if the raycast collides with something and positioning it there. Only caveiot to this is that it’ll likely only move from one direction (which could be fixed if you increment from 10 studs → 20 studs → 30 studs and so on, but not sure if you’ll want that) and it can’t check corners (unless you want to add more raycasts to check the corners)

EDIT
Or you can just unachored the HumRoot when it hits the floor