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: https://www.babylonjs-playground.com/#Z0QW21#7.
Thanks for any help.
Givo
PS. the game will play much differently than others.
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.
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. This looks awesome, man; keep up the cool work!
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!)