Apply Force Where Camera Looking

I want to apply force where my player is looking…

Hi there, Jack

Apply force to what? The player entity? if so, maybe this tutorial will help:

Make sure to take a look at the tutorial section in the Docs Tutorials | Learn PlayCanvas

Hi @Francisco_Bozzo i make game where my player throwing ball now but problem is that my player throw ball in one direction . i want where my camera is looking player throw ball there

Hi there

Ok, you can do something like:  ="Camera");

EDIT: in this case you need to do the “mulScalar(-1)” to invert the orientation because “forward” goes to the negative Z axis direction.

The key here is applying force to one entity based on the orientation of another entity. Then you can play around with variations.


I apply but its not working i want to throw ball where my camera in looking in fps

here is my project link can you help me in this
in scene ballthrow

Ok, if you describe how exactly you want this to work I can set it up for you.


@Francisco_Bozzo Thanks Man
fps player who can pick ball when i click on ball and throw any where he want and where he look i look up ball throw up i look down ball throw down and if i look any where ball throw on that side where i am looking.

Could you add me to the proyect so I can help you setting that up?

my username is grisco

Okay i add you please check

Sorry, I made a fork and made some changes. I hope you find them usefull but of course feel free to go back to what you were doing!

The main issue here was that when you disable the rigidbody, its linearVelocity property stays. So when you re-enable the rigidbody, it gets affected by it’s previous velocity. You’d have to wait for the ball so stop moving completely before picking it up after every throw.

so the line of code that fixed it all was
this.movingEntity.rigidbody.linearVelocity = pc.Vec3.ZERO

Also I made some changes to the script so you can reference all the objects you would want to to be “pickable” in your scene. So you don’t just check upon their names when you raycast, but instead you check updon their “isPickable” property.

1 Like

@Francisco_Bozzo Man Really Thank you so much :hearts: :hearts: :hearts: