[SOLVED] Collision pick up

Can I see your project please?

sure

thie object is behind you down the object is a hammer
https://launch.playcanvas.com/1311766?debug=true

I fixed it
all I had to do was move the point entity up a little

Great, good job!

How do I make it so I can put it down

oh and thank you

Reparent it again but to your Root entity this time.

so the same script but what root entity in what object

also dont I have to press a button to put it down

No not the same script, because you don’t need a collision check for this.

will it go in front of the player or back to its regular position
also I can pick it up again right

It wil stay on the position where you reparent it. You only can pick it up again if you set this.pickedUp to false again. I suggest to expand the script with an update function where you can do these things.

your gona have to write it out for me sorry

You have to try the things I suggest yourself first.

so in the update function

if(this.app.mouse.waspressed(pc.MOUSERIGHT){
this.app.entity.setpickedup == false

For the mouse button you don’t need the update function.

In the initialize function:

this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);

And add this function to the script:

Pickable.prototype.onMouseDown = function (event) {
    if (event.button === pc.MOUSEBUTTON_RIGHT) {  
        this.entity.reparent(this.app.root.findByName('Root'));
        this.pickedUp = false;
    }
};

ok thanks

I have fixed a mistake in the code above.

// initialize code called once per entity

Pickable.prototype.initialize = function () {

Would I put the first code in the brakets and then underneath put the second code?