I am making a shooter game using threejs but i don’t know how to make the balls bounce
Heres the link
Easiest is to use fake bouncing:
ball.position.y = 0.2+5*Math.abs(Math.sin(t/500));
where you have to give proper values instead of
- 0.2 - radius of ball
- 5 - height of bounce
- 500 - speed of bouncing
- t - time in ms
When I started with three.js about 8 years ago, I wanted to see if I could make a simple game with it.
I don’t play games myself, I was interested in geometry and movement.
However, at that time I wrote everything in German. But with https://www.deepl.com/ for example, you can easily translate things.
Androids Ring Tennis (Beta): Androiden
For the ball throw, the functions
German => translated
wurfparabel_ww( … => throwing_parabola_ww( …
abstand_xz( … => distance_xz( …
richtung_xz(… => direction_xz(…
are of interest.
Punkte => points
The instructions translated:
Androids Ring Tennis (Beta)
Mouse and cursor keys control camera.
Mouse and buttons g r l j c w control android and throw:
g - go straight ahead, mouse body
r - turn right, mouse left arm
l - turn left, mouse right arm
j - turn arc to the right,
c - arc to the left,
w - change throwing distance (close to the ball)
Play the ball over the bar once and watch! The android and the scoreboard can be controlled with the mouse.
To begin with, simply hold down the g button and see what happens.
I didn’t develop the game to completion and it corresponds to my beginner level at the time.
I like this samples implementation of ball shooting/collision etc:
https://threejs.org/examples/?q=fps#games_fps
Maybe there are some ideas you can get from it.