Path: chuka.playstation.co.uk!news From: richard.cutting@virgin.net (Richard Cutting) Newsgroups: scee.yaroze.beginners Subject: Re: Wheeee!!! Throwing actions ! Date: Mon, 05 Oct 1998 22:50:39 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 73 Message-ID: <36194791.17530092@news.playstation.co.uk> References: <6vbdji$rda1@chuka.playstation.co.uk> NNTP-Posting-Host: p31-shoveler-gui.tch.virgin.net X-Newsreader: Forte Free Agent 1.11/32.235 On Mon, 5 Oct 1998 22:31:38 +0100, "Tones" wrote: >Hello all, > >Once again I speak after having a little trouble with yet another trivial >problem. This time it is programming a particular fuction. Throwing an >object! (I'm sure all you guys must think I am totally incompetant, having >posted a number of requests for help b4 ('bout 3 I think?)!) > >Basically, when I press X I want to be able to throw an object, which then >becomes totally independent in it's flight path. I have used a fuction to >tell the program that the object has now been thrown (I use a simple array >to do this), but what method would I use to calculate it's trajectory from >Player1.x and Player1.y if I want it to go up a little in the direction the >player is facing, then obviously fall back to the ground according to Mr >Isaac Newton's law of gravity ? I.e. an arc of some kind. > >I have tried a number of things, such as calulating the x and y positions, >sticking these in a structured array, then access each successive >co-ordinate on each pass of the fuction. However, this take's up a bit of >time (in programming terms, not actually on the screen - as I use a for >loop). I have also thought of using a Sine wave table, but this is a little >beyond my capabilities. > >In quick terms, I need pointing (HaHa! Oops, no pun intended :( ) in the >right direction. > >Otherwise, you may be pleased to learn my game is coming on quite nicely - >Apples & Pears!!!! > >Many thanks in advance, > >Tones : ) > > All you need to do is to calculate the x and y velocities for the object as if it were chucked in a straight line and then apply wind and gravity so it falls back to earth. You can do this using some simple maths. To get the x and y velociities you use; xv = sin( angle ) * magnitude yv = cos( angle ) * magnitude where angle is the angle relative to the horizon and magnitude is the speed. ( I may have got sin and cos the wrong way round, but it's late and I'm knackered.... ) Then to calculate the x and y positions you just apply wind to the x and gravity to the y. I.e; x_position = x_position + xv + wind y_position = y_position + yv + gravity ( where gravity is a fixed constant and wind is whatever you want ! ) This would be done every game cycle. For speed reasons you want to steer well clear of the Yaroze's sin and cos library functions. I recommend that you grab James Shaughnessy's SINCOS.H file from his home page ( http://www.netyaroze-europe.com/~shaughnj ) which gives you tables containing a fixed point implementation. You have to do a bit of bit shifting to use them but it's not difficult. Richard ( Who's really needs to dig out his basic maths books !! ) http://www.netyaroze-europe.com/~rcutting