Welcome to Dream.In.Code
Getting Help is Easy!

Join 105,408 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,762 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Aaaaargh 3d tennis

 
Reply to this topicStart new topic

Aaaaargh 3d tennis, problem with gravity

stayscrisp
post 27 Jun, 2008 - 03:30 AM
Post #1


D.I.C Head

**
Joined: 14 Feb, 2008
Posts: 179



Thanked 4 times
My Contributions


My 3d tennis game is currently more like a 2d tennis game as my ball never uses gravity for its y values at the minute, it moves only left and right and forward and back, not up and down. I have the collision detection pretty much sorted for all the objects and the ball stays within its confines. As soon as i introduce gravity my ball is apparently colliding with floor level even though i am not checking for a collision like this :s

and as soon as it bounds of the floor it just flies up in the air and doesnt come back down, now my understanding is that gravity is a pretty simple effect to achieve even in 3d, just a case of decreasing the y values of an object by however many units per second or something. This is exactly how i implemented it

CODE


// this is called in the update function for the ball(every frame), it moves the ball in x
// and z by adding to the values by delta time * the cos of angle0 * the ball speed, angle0 is a value returned by my
// reflect function, which gives realistic bouncing angles from players and barriers
x0 += dt * cos(angle0) * BALL_SPEED;
z0 += dt * sin(angle0) * BALL_SPEED;
y0 -= dt * BALL_SPEED;


then when the ball reaches floor level its y increases by a certain amount to give the bounce effect
should work right :s
i have even tried hard coding a max y for the ball that i thought might bring it back down, i even tried some boolean variables for climbing and falling, i have no clue why it doesnt want to work
any help is greatly appreciated, im using c++ and opengl

thanks

User is online!Profile CardPM

Go to the top of the page


Tom9729
post 27 Jun, 2008 - 12:58 PM
Post #2


Debian guru

Group Icon
Joined: 30 Dec, 2007
Posts: 1,382



Thanked 7 times

Dream Kudos: 325
My Contributions


http://en.wikibooks.org/wiki/FHSST_Physics:Index smile.gif
User is offlineProfile CardPM

Go to the top of the page

stayscrisp
post 28 Jun, 2008 - 08:23 AM
Post #3


D.I.C Head

**
Joined: 14 Feb, 2008
Posts: 179



Thanked 4 times
My Contributions


its not the physics i dont understand its my code, thanks though.

i know the physics, its gravity.

I will solve it hopefully soon, my game is leaking like a bucket as well and its gotta be handed in in 3 weeks :s
User is online!Profile CardPM

Go to the top of the page

Tom9729
post 28 Jun, 2008 - 01:57 PM
Post #4


Debian guru

Group Icon
Joined: 30 Dec, 2007
Posts: 1,382



Thanked 7 times

Dream Kudos: 325
My Contributions


I only posted it because of this:
QUOTE
then when the ball reaches floor level its y increases by a certain amount to give the bounce effect
should work right :s


The bounce (assuming it's perfectly elastic, and that I understand what you're talking about smile.gif) should preserve the speed of the ball and just change it's direction.

Gravity should just be used to accelerate objects downwards.

Bounces should be based upon collisions. If your court is a level plane at y=0 then you can test for when the ball's y=0, and flip the sign of it's vertical speed.
User is offlineProfile CardPM

Go to the top of the page

stayscrisp
post 28 Jun, 2008 - 03:28 PM
Post #5


D.I.C Head

**
Joined: 14 Feb, 2008
Posts: 179



Thanked 4 times
My Contributions


sorry that was my bad explanation :s

what i meant was that gravity would decrease the y and then the collision would add to the y by a certain amount before the gravity would take it back down again. I just dont get it though i have implemented this tons of times with no problems but this just wont do it, and i havnt even implemented the floor collision yet :s very odd.

and im not typecasting my objects for collisions detection which might explain the floor detection, ill ask my lecturer on monday, cheers for the help tho smile.gif
User is online!Profile CardPM

Go to the top of the page

Tom9729
post 28 Jun, 2008 - 03:52 PM
Post #6


Debian guru

Group Icon
Joined: 30 Dec, 2007
Posts: 1,382



Thanked 7 times

Dream Kudos: 325
My Contributions


It's okay, physics in games can be confusing. It's one thing to solve a problem for a fixed scenario (like a practice problem in class), but writing a solution that can dynamically change based upon the input is hard. icon_up.gif

This post has been edited by Tom9729: 28 Jun, 2008 - 03:52 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/20/08 05:19AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month