The Daily Click ::. Forums ::. Klik Coding Help ::. 360 gravity
 

Post Reply  Post Oekaki 
 

Posted By Message

CUBE



Registered
  04/12/2004
Points
  283
3rd February, 2006 at 07:28:21 -

What would the best way to apply gravity to a grenade that can be fired in 360 directions?
And it's side view as well, if you need to know...

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
3rd February, 2006 at 07:40:19 -

Define 'best.' Do you mean most realistic, or best tradeoff between looking fairly real and not being arsed to code it properly?

 
n/a

CUBE



Registered
  04/12/2004
Points
  283
3rd February, 2006 at 07:42:45 -

I need the most realistic way

 
n/a

Teapot

Does he even go here

Registered
  02/10/2003
Points
  2631

VIP Member
3rd February, 2006 at 22:11:10 -

Give it an Alterable avlue for it's Z position. Then treat the gravity like you would a platform game. Of course that's only a basic explanation.

 
n/a

CUBE



Registered
  04/12/2004
Points
  283
3rd February, 2006 at 23:53:19 -

That kinda worked, but it didn't seem to like decimals... Can alterable values hold decimals?

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
4th February, 2006 at 01:07:35 -

Yeah, use alterable values for any movement that's going to need decimals, always. You need to convince MMF into storing them by including a decimal in the calculation; ie. 1 + 2.0 instead of 1 + 2.

 
n/a

CUBE



Registered
  04/12/2004
Points
  283
4th February, 2006 at 07:54:15 -

Ok, it works fine now, thanks for the help

 
n/a

ben mercer

Possibly Insane

Registered
  11/07/2004
Points
  2538
4th February, 2006 at 12:00:50 -

The game is side view you say? You need to assign x and y velocities and positional values to your grenade. Basically, you do this.

When your grenade is fired-

set xvel to cos(angle) * power of throw
set yvel to sin(angle) * power of throw

And then your gravity is simply-

always set yvel to yvel + gravity (as a float value such as 2.0)

You also need to alter your positions accordingly

always set xpos to xpos + xvel
always set ypos to ypos + yvel

If you find that your grenade can pass through thin walls, you need to use a loop like this.

always start move loop 20 times

on move loop-
set xpos to xpos + xvel/20.0
set ypos to ypos + yvel/20.0

If it's a side view game, i think you needn't bother with a z position. If you just use a y position and not a velocity, it is not realistic.

Also i thought i'd add that to give the grenade a terminal velocity (i.e it doesnt just keep accelerating) you add a simple air resistance solution:

always set xvel to xvel / 1.05
always set yvel to yvel / 1.05

Image Edited by the Author.

 
Stuckboy

JC Denton: "I know your UNATCO killphrase: Laputan Machine."
Gunther Hermann: "I - am - not - a - machi --"
JC Denton: "Sticks and stones..."

Teapot

Does he even go here

Registered
  02/10/2003
Points
  2631

VIP Member
5th February, 2006 at 05:08:13 -

Woah it's side view? I thought it was top view. So my Z thing was overly-complicated.

 
n/a

CUBE



Registered
  04/12/2004
Points
  283
5th February, 2006 at 08:08:54 -

Yeah, but I did it the way you said, Teapot.. But I was wondering why you said to have a Z value...

 
n/a
   

Post Reply



 



Advertisement

Worth A Click