Code for Grabbing objects

Hellooo i wuz wondering if anyone could help me make a script that makes it so you can click an object and it will go to your cursor and then stop and fall down afterwards

Hi @Orange_Test_Room,

You can take a look at the entity picking tutorials in the Tutorials section. Here is one using physics:

https://developer.playcanvas.com/en/tutorials/entity-picking-using-physics/

This will allow you to click and select an entity. From there you can start moving that entity to follow the mouse cursor.

this entire time i looked at that and never realized you could move it! Man im dumb

i can click the netity but it doent move i tried dragging it and things

Yes you will have to code dragging, the tutorial above is a starting point for entity picking.

This is a useful method that works on your camera component to return a world position based on screen coordinates. You can pass the mouse cursor coordinates and reposition the selected entity in the world.

https://developer.playcanvas.com/en/api/pc.CameraComponent.html#screenToWorld

1 Like