Is VoxelComponent:SetVoxel working in local space or world space?

While playing around with trying to place voxels which follow the player i spend a while trying to figure out why the logic seemed correct but the resulting voxels were being drawn in the wrong place, After setting the position of the object running my voxel script to 0,0,0 all started to work as intended,

For example i was telling my voxel to start at 0,0,0, when my object was not at 0,0,0 and move towards the player at 25 units a every 3 frames,

Can i just ask is the pos taken by VoxelComponent:SetVoxel working in the local space of the entity you use to call it, and if so could we get the docs to note this is the case?

Also do we have a limit on how many voxels we can create at once, I found when i created 1 voxel every 3 frames they would appear when requested but when i tried to draw 1 voxel a frame, the system would appear to queue up the requests are process them all in a single frame at a later time,

1 Like

I’ve been having a separate issue, but your question gives me hope that it can be done! I’m new to lua, and also Crayta (obviously).

Would you mind posting the lua code you are using to set voxels. I seem to be getting all sorts of errors. I think my main issue is that I don’t understand how to get hold of a VoxelAsset to pass to the SetVoxelBox method.

Many thanks!

So what i have done is create a voxel mesh that is just a single square then called self:GetEntity():SetVoxel, and this creates the voxel

image
properties.head is of type “voxelasset”

1 Like

Ahh, thanks very much. I’ll try that out tomorrow.

In an effort to try to help you with your problem - the API docs says SetVoxel “Server Change a single voxel in world space.” - so the answer to your first question seems to be world space. There may also be a clue about the number of voxels you can change - it seems that voxels are edited on the server, then at some point the clients update somehow. Perhaps that might give you a clue towards what is going on.

It’s probably not much help - but hopefully it helps a little.

Thanks again!

Yer that comment made me think WS too but while playing with it, if i take a WS position and cast it back into LS, (or have the object at 0,0,0) it appears to do what i expect

I have been struggling with this for days. I am trying to spawn one voxel from a global script.

In roblox you create script in the workspace, and then that script instance the block, color, vector3 etc

Can someone explain how this is done, or just upload a package would be so helpfull


This is the code I am using the spawn a single voxel in the world since I feel the function is working in the local space of the object it’s connected too i’m converting the worldspace pos into local space,
A break down of what each value is:
self.tbodyParts[1] is Vector, this is where i want the voxel to be drawn,
self.entityStartPos is a Vector, this is the position of the entity running the script

local posToDrawInLs is just a local space location of where we want to draw the voxel,
Explanation of Local vs Global space

I called ResetVoxels() as i wish for every voxel I have drawn before this to be cleared, depending on your use case you may want this you may not

self.properties.head is
image

This script is attached to a voxelMesh, (you can just attach it to your floor as the default one is a voxel mesh)

Hope this helps, if you have any question feel free to ask here, or if I’m near my pc il normally be floating around in the Crayta discord feel free to poke me there, https://discord.gg/crayta

Thanks so much! I will work on this!