Shoot projectile in camera camera's direction


Due to my laziness I’ve taken a drastic turn for my game(surprise reveal coming soon) and I need help. How do I make it so i shoot a ball in the camera’s forward direction on a left click? any help would be nice. I’ve got the shoot part but it doesn’t work with left click and not in the right direction. my playerground is this:

Thanks for any help.


PS. the game will play much differently than others.:slightly_smiling_face::grinning::wink:

Hi Givo,

The right-click-to-shoot mechanic is a little jarring at first, but that might be the design. I fiddled with it a little and think I got something interesting.

This is really almost exactly what you had before, I think I only changed a few things:

  • The int value for the left button is 0, I believe. Not sure why there isn’t a link to that in the doc (that API might be deprecated), but 1 is often reserved for the “middle mouse button” which doesn’t exist on most modern mice. :upside_down_face:
  • In the call to translate(), I passed in the direction from getForwardRay(), which gives a world-space vector for the direction the camera’s facing.
  • Since getForwardRay()'s output is already in world-space, you shouldn’t need to transform the force inside translate() (unless I’m misunderstanding the purpose of that), so I removed that call from there.

Also, once I got the ball shooting, plinking away the stacked balls in the middle was surprisingly fun, so I felt the need to turn up the shooting force and plink away for a while. :smiley: This looks awesome, man; keep up the cool work!

Hey thanks! a couple things.

I know, but for some reason this mouse click api code had it at one. for mouses it is left=0, middle=1, right=2. (yes, the plural of computer mouse is mouses. Look it up! Then proceed to mess with the people you know!:laughing:)

It’s not. I couldn’t get left click to work.:upside_down_face:

The first thing I did was stack a whole bunch:
Then did this:

It is cool to see how cannon.js squashes sphere impostors. Wait a little and look up. ball cascade heaven.

The game is based around this shooting mechanic. I’ll add you to a private message about it.

Thanks for the help!