Would this be expensive for client usage?

Hey, so I might go ahead and try this at some point just to see if it doesn’t cause lag spikes, but let me give you an overview of what I’m trying to accomplish.

So, in a game I’ve been working on, there’s going to be a feature where the player can move these crate objects, but there’s additional behavior attached with that where messing with Roblox’s physics isn’t going to work, so I’m gonna use CFrame for the crate movement.

So, if the player moves forward, I’ll need to cast a ray from the player’s facing direction seeing if there’s an object in front of him. Now, this is what I originally thought of trying. If there is an object in front of the player, I could then create a small Region3 the size being the object’s bounding box, and I’d position the Region3 from where the crate is, but I’d apply an offset to it based on how much the crate would move if the player pushed it successfully. This would be to avoid collision, and if there was a collision detected in the Region3, the player wouldn’t move the crate.

However, creating the new Region3s would not happen every frame. Only if an object is detected in front of the player and if the player is currently moving.

Not sure if this would cause performance issues, I might try it any ways just to see, as this sounds like the most reliable way of knowing if there’s going to be a collision at the moved object position.

Thanks!

1 Like

What are you trying to achieve as an end goal?

Idea 1 of what your trying to do because its slightly confusing:
So essentially you want to create boxes of different masses which when touched will move specific distances?

Also why would you need to raycast if this is the case, could you not just capture when the box is being moved and then handle it at that moment?

e.g. BasePart.Touched

General answer to your method:
It depends really on how big the object is, how much collisions + maths the server has to do on your end and generally how much processing power it takes to handle your physics. Seeming as it would be using steps, it shouldn’t be too expensive on the client → but then it genuinely depends how much actually is being done on the client and on the server.

I know for example:

local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position)

if withinScreenBounds then
   -- Player sees part so operate
end

Has little to no effect when placed in a recursive while loop.

2 Likes