Spawn object where you click

I need help I’m trying to make code where when you click an object spawns where you click

If you would like to spawn a drawing object like a cube or sphere, you can use the following code:

Time.scheduleRepeating(() =>{
const rayCastHit = RayCast.cast( Camera.transform.position , Input.clickDirection );
if (rayCastHit && rayCastHit.item.name == “ground”){
Input.onKeyPressed(()=>{let cube = Scene.createCuboid(rayCastHit.point)},“left_mouse_button”);
} }

But if you would like to spawn BaseItems or other objects, you will need to hide the original somewhere and spawn its copies on the click position.
I hope this example is helpful: JRZ-BDC

2 Likes

how would i spawn coped objects and do you know if I could spawn them on a grid

Hi @Matthew_Leach, here is the link to one of the @Jaewoo’s Python masterpieces where he spawns copied objects. For a spawning on a grid, you would need I believe an array. How - it really depends on the project itself.
Good luck!

thank you for helping

This might help:

wow thank you for helping this was what i was trying to make

and do you know if you could delete the blocks

If in CoBlocks, you simply use the Delete Item block and delete the copy. In TypeScript it would be similar. The key would be activating and deactivating the Delete function with a keypress, then use right-click to remove.

I did this Time.scheduleRepeating(() =>{const rayCastHit = RayCast.cast( Camera.transform.position , Input.clickDirection );
Input.onKeyPressed(delete(rayCastHit.item), “r”); void
}
but it wont work

See BaseItem | CoSpaces API - delete is a method of the BaseItem object, not a standalone function.

In your code, scheduleRepeating is a method of the Time object.