Realistic Falling off Platform Physics

Started by
10 comments, last by Jacob Roman 19 years, 5 months ago
I'm making a fighting game where fighters can fall off of the platform. Currently, my physics model for falling is this:


            Sprite(1).Animation_State(Sprite(1).State).Acceleration = Gravity
            
            Sprite(Current_Sprite).Y = Sprite(Current_Sprite).Y + Sprite(1).Animation_State(Sprite(1).State).Velocity.Y
            
            Sprite(1).Animation_State(Sprite(1).State).Velocity.Y = Sprite(1).Animation_State(Sprite(1).State).Velocity.Y - (Sprite(1).Mass * Sprite(1).Animation_State(Sprite(1).State).Acceleration)
            
            If Sprite(Current_Sprite).Y <= -99990 Then
            
                Sprite(Current_Sprite).Y = -99990
                
                Sprite(Current_Sprite).Animation_Enabled = False
                
            End If



That right there just does a straight freefall with no X Velocity. And it causes the sprite to accelerate faster and faster the further down he falls. Here is what I really want though. Let's say the fighter is walking backwards and falls off as a result. Since the fighter has Velocity walking backwards, as a result, it should cause the X'ward Velocity to (forgive me in terminology if I'm wrong) Deccelerate as the fighter falls down. Obviously this will form a parabola. Now I've had a couple in mind, but for some reason, I can't blend this in too well with my falling physics, which seems to be right: Y = -X ^ 2 (Where X increments by 1) If you put this in a graphing calculator, it'll form an upside down "U" kind of parabola. Now since (0,0) is in the center of the graph (same goes for my arena in my game), only half (vertical half by the way) of that upside down "U" shows it falling in the Y direction and making it look as though the X velocity is slowing down, only it's not. When I put this in my game, trying to somewhat blend it in with the current physics equation that I have as an experiment, it caused it to fall instantly, which was not what I wanted. How do I do this correctly?
Advertisement
this may be totally off the mark, but why not perform physics based on standard assumptions. I assume i already have a directional vector. Now the x-component can be affected by drag/friction and the y-component is affected by gravity.

since y is by gravity, a natural acceleration will occur, hence ur characters will drop faster and faster. of course, realistically, there is also friction which opposes the fall, so that should cap ur drop velocity eventually.

ur x-component however is affected purely by friction/drag. How much drag is set is up to you, but that will incur a natural decelleration in the x-direction.

wat this essentially means is ur x- and y- are NOT related, which shud be the case in real life. just because ur are further left doesnt mean u'll drop faster :P try treatng them as separate entities with their own factors. u shud get a parabolic behavior. do a google on 'projectile motion' to get an idea of this.
- To learn, we share... Give some to take some -
Yeah you are right. I had to treat them as separate entities and add friction to it. Here is what I've added:

            If Sprite(Current_Sprite).X < -1000 Then                            Sprite(Current_Sprite).X = Sprite(Current_Sprite).X - Sprite(Current_Sprite).Animation_State(Sprite(1).State).Velocity.X                                Sprite(Current_Sprite).X = Sprite(Current_Sprite).X - Sprite(Current_Sprite).Animation_State(Sprite(1).State).Friction.X                            ElseIf (Sprite(Current_Sprite).X > 1000 + Sprite(Current_Sprite).Width) Then                            Sprite(Current_Sprite).X = Sprite(Current_Sprite).X + Sprite(Current_Sprite).Animation_State(Sprite(1).State).Velocity.X                                Sprite(Current_Sprite).X = Sprite(Current_Sprite).X + Sprite(Current_Sprite).Animation_State(Sprite(1).State).Friction.X                            End If


Where friction is a negative decimal and Velocity is a positive decimal. It's working really well now. Was this the correct way of applying friction though?
Oh shoot, I just realized it is wrong. I have to slow the X Velocity down as well. Give me a minute. I think I know what to do...
Nope, it didn't work. How do I slow down the X Velocity to where the friction will cause the X Velocity to go slower and slower? This is as opposed to where gravity causes objects to accelerate faster and faster.
talking in pure physics terms the drag due to air resistance would be that small its hardly noticeable, therefor the x velocity is unchanged, the parabola is formed by the changing y value
talking in pure physics terms the drag due to air resistance would be that small its hardly noticeable, therefor the x velocity is unchanged, the parabola is formed by the changing y value
Ok, I may have almost got it. Here is what I have now:

            If Sprite(Current_Sprite).X < -1000 Then                            Sprite(Current_Sprite).X = Sprite(Current_Sprite).X - Sprite(1).Animation_State(Sprite(1).State).Velocity.X                                Sprite(1).Animation_State(Sprite(1).State).Velocity.X = Sprite(1).Animation_State(Sprite(1).State).Velocity.X * Sprite(Current_Sprite).Animation_State(Sprite(1).State).Friction.X                            ElseIf (Sprite(Current_Sprite).X > 1000 + Sprite(Current_Sprite).Width) Then                            Sprite(Current_Sprite).X = Sprite(Current_Sprite).X + Sprite(1).Animation_State(Sprite(1).State).Velocity.X                                Sprite(1).Animation_State(Sprite(1).State).Velocity.X = Sprite(1).Animation_State(Sprite(1).State).Velocity.X * Sprite(Current_Sprite).Animation_State(Sprite(1).State).Friction.X                            End If


I just found out the formula for friction which is this

Friction = u * Normal Force

where u is the coefficient of friction. It's still a little trouble though. Maybe if I play around with the friction values...
It worked! Just used a friction value of .99
Hi,
just saw the following line in your code:

Sprite(1).Animation_State(Sprite(1).State).Velocity.Y = Sprite(1).Animation_State(Sprite(1).State).Velocity.Y - (Sprite(1).Mass * Sprite(1).Animation_State(Sprite(1).State).Acceleration)

or simplified

Vy = Vy - m*a

if you want to be physically correct that formula would be wrong since your change in velocity depends on the mass of the object, which is not the case for real objects (in case of constant acceleration like gravity for example. For a constant force it would depend on mass: a=F/m). Better would be something like

Vy = Vy - a*dt
where dt is the timestep since your last update.

This topic is closed to new replies.

Advertisement