Modify Picker_raycast script

Hi! @Albertos, I have been trying to add the ability to throw the entity. I am struggling with the timer and how to make it move forward. If I hold the mouse for 2 seconds or more, when I release the mouse the right mouse button the entity would fly forward away from the player.

In the tutorial project below, something similar has been done, to detect a double click. Maybe it can help you.

https://developer.playcanvas.com/en/tutorials/detecting-a-double-click/

You can apply an impulse after the rigidbody type is set back to dynamic.

https://developer.playcanvas.com/en/tutorials/Using-forces-on-rigid-bodies/

I have made it more simple, If I press the right and left mouse at the same time I throw it. could I do something like apply force?

Maybe more simple for you, but what about the users perspective?

You can apply a force on the rigidbody as long as the type of the rigidbody is dynamic at that moment. So be aware that if you drag an entity, the type of the rigidbody is temporary set to kinematic with the script.

image Maybe more simple for you, but what about the users perspective?

I am going to add a menu telling all the controls for the game

if(this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT && MOUSEBUTTON_RIGHT)){
     this.pickedEntity.rigidbody.type = 'dynamic';
     this.pickedEntity.applyForce(0,0,5);
};

A few points of interest:

  • The if statement need to be the same for the right as for the left.
  • You need to apply the force on the rigidbody of the entity.
  • applyForce need to be applyImpulse in this case.
  • The ; sign at the end of the statement is not correct.

what do you mean by it needs to be the same

I need 2 if statements?

No, after the && sign need to be the same as before the && sign.