Hi everybody,
I am interested into the creation of a 2D volley ball game, which as to be as realistic as possible.
In first, i want to create a prototype which allow to :
- display 2 circleshapes ( 1 ball and 1 player )
- player shape is located on the bottom on the screen and we can just make him moving left or right, and jumping by a realistic way( i mean with gravity )
- ball shape spawn in top of screen and fall with gravity; it has also to rebound with player, walls and ground
What I already have:
- player shape which move left or right, and a basic jump implemented:
( i want a real jump so i check on the internet to find equations, i found something like
y=y0 -(1/2*g*t*t) + v*t )
- every collisions test
- rebound against walls
I also have a formula to calculate rebound between two circles but i haven't implemented it at the moment;
So my questions are :
- is it best to use " myObject.move(mySpeed) " or " myObject.setPosition(x,y) " ?
- by trying to implement a realistic jump, i did this :
if(inAir)
speed.y+=k*grav*clock.getElapsedTime().asSeconds();
where k is a fixed constant,
grav is equal to 9.81
But I have some difficulties with modiying speed.y when the player is on the ground and want to jump...
For example, when do i have to do a clock.restart() ?
Thank you for advance,
Have a good day !