Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Black Wolf on June 11, 2004, 01:20:28 am

Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on June 11, 2004, 01:20:28 am
OK. By now, everyone's seen the TI atmospheric pics. The first question everyone seems to ask is "Will there be gravity?". And so far, I've had to say no, because there really wasn't any way to do it convincingly. We messed around with stuff like invisible kinetic weapons firing at you from great distance and stuff, but nothing seemed feasible. Then last night, I was sitting around and realized I was an idiot.

Code: [Select]
when
 - true
 - Set-Ship-position
    - Alpha 1
    - Get Position X
       - Alpha 1
    - -
       - Get-position-Y
          - Alpha 1
       - 25
    - Get Position Z
       - Alpha 1
Repeat Count 9999, Interval 1


The basic pemise was that every second, the sexp would shift the player down 25 meters. And it worked. It didn't accelerate like true gravity would, but it was as well simulated gravity as we're ever likely to get without a complete physics engine overhaul. There was only one problem. It worked as well as could be expected given what I told it to do, ie. Instantaneously shift down 25m every second. In other words, it's very, very jerky and obvious.

There are two ways I can think of to fix it. One is to implement a "move-ship" sexp, that would shift the ship naturally, as opposed to just putting it in position, however, I'm assuming this isn't as easy as it would sound, or you'd have done it, and other related sexps (like "rotate-ship-facing as opposed to set-ship-facing) by now.

The other was to do something a little sneaky. The huma eye only sees something like 15 or 20 FPS - the greater the frames fer second above that, of course, the smoother the transitions look, but once you pass about 10 or 15, things start to look decent. So, I figured the easiest way top make this happen would be to decrease the allowed interval between sexps to .1 or .05, and increase the number of allowed repeats by an equivalent amount (ie to 99999, or 200000). It wouldn't break backwards compatability, since the numbers would stay thge same, the only thing I'm worried about is that V might have limited you to 1 second intervals for a reason.

I know this seems very campaign specific, and I know you guys don't like making those kinds of changes, but I know there are other missions where I could use either of these (other than the atmospheric stuff), so it's entirely possible other people will find uses for them as well. I know that's kind of thin (though true), but it's the best I could come up with on short notice. :)
Title: Gravity - with (I hope) very minor code changes.
Post by: WMCoolmon on June 11, 2004, 01:58:47 am
You'd also have to implement an any-ship operator in place of Alpha 1. But, that would be pretty easy from a coding point of view.
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on June 11, 2004, 02:06:06 am
Actually, I'm not so sure about that - I really don't know how the AI would react to this, so limiting it to the player would probably be an acceptable compromise.

I would like a "velocity" returner, so that it could be applied only once the players speed drops below, say, 20 m/s, but if neccesary I can probably fudge it with the "speed" returner (which requires the set-training-context-speed sexp as well) (and frankly is pretty crappy) and the alternating On/Off variable method I worked out (And Karajorma made work :)) for the other topic.

That said, the "any-ship" would be very useful, but I think Goober or somebody was working on it (or planning to). I posted something about it a few weeks back.

EDIT - Yep http://www.hard-light.net/forums/index.php/topic,23543.0.html
Title: Gravity - with (I hope) very minor code changes.
Post by: WMCoolmon on June 11, 2004, 02:08:39 am
Could you do it with a get-current-speed sexp?
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on June 11, 2004, 02:12:40 am
Is there a get-current-speed-sexp? (I'm using a fairly elderly version of FREDOpen - need to update)

Oh, and yes. Assuming it works the same as get-position-X or whatever, then it'd be ideal.
Title: Gravity - with (I hope) very minor code changes.
Post by: Lightspeed on June 11, 2004, 12:46:48 pm
Best would be to automise all that and put it in a FRED setting, so you wont have to fiddle with the SEXPs anytime, but FRED does all the work for you.
Title: Gravity - with (I hope) very minor code changes.
Post by: aldo_14 on June 11, 2004, 02:14:50 pm
someone told me Darkage got a gravity effect using a constantly fired bomb with a huge blast radius and very large negative shockwave.

NB:  I was working on an atmospheric mod till recently, but dumped it because of the whole gravity thing (specifically, the debris).
Title: Gravity - with (I hope) very minor code changes.
Post by: Lightspeed on June 11, 2004, 07:37:24 pm
BlackWolf:

I just had an idea. It should be possible to have the drop-down distance increased over time if it used another variable.

You could change the gravitation drop down according to the speed of your vessel, and according to its Y position.

I.e. get-y-position gives you the Y-location of the ship. You could make a multiplyer from that that goes into the Place ship thingy.

This would allow you to use acelerated gravity - it's fake of course, but a much better fake (as gravity would seemingly get stronger the lower youre flying).

You'll of course have to do a lot of tweaking and such to get it working properly.
Title: Gravity - with (I hope) very minor code changes.
Post by: WMCoolmon on June 11, 2004, 08:23:54 pm
Quote
Originally posted by Black Wolf
Is there a get-current-speed-sexp? (I'm using a fairly elderly version of FREDOpen - need to update)

Oh, and yes. Assuming it works the same as get-position-X or whatever, then it'd be ideal.


I don't think so, but since the HUD displays that exact information already it should be easy to add a SEXP like that.
Title: Gravity - with (I hope) very minor code changes.
Post by: Jetmech Jr. on June 11, 2004, 09:18:26 pm
Would this conflict with AI? Like, say, youd have capships slowly drifting down to crash into the ground? Or am I just spouting drivel?
Title: Gravity - with (I hope) very minor code changes.
Post by: Gregster2k on June 11, 2004, 10:08:38 pm
From what I'm reading here it will only affect ships you tell it to affect...this could be interesting, especially if one wanted to simulate the crashing of a capital ship after its antigrav generators fail...or whatnot. :) I know Star Trek ships have antigrav, so this would work nicely for THAT :)
Title: Gravity - with (I hope) very minor code changes.
Post by: HotSnoJ on June 11, 2004, 10:09:09 pm
OMG!! This shoud be news ppl!! Printed on the front of ever newspaper in the world, and plastered all over the front page of HLP!!
Title: Gravity - with (I hope) very minor code changes.
Post by: Gregster2k on June 11, 2004, 10:10:36 pm
mmm...this is indeed a breakthrough. With this you could create "turbulence effects" in nebula clouds, as well. Just um, like, randomize it a bit (or something) voila.
Title: Gravity - with (I hope) very minor code changes.
Post by: HotSnoJ on June 11, 2004, 10:18:16 pm
Yay, me again. Though this is more of a question to the coders.

If we know the mission 'world's' X, Y, and Z coordinates, why couldn't something like this be coded into the engine long ago? [/idiot talk]


Go Black Wolf! YOU.ARE.AWESOME.!
Title: Gravity - with (I hope) very minor code changes.
Post by: Setekh on June 12, 2004, 12:32:35 am
HotSnoJ, just a word of advice - add a link into your news post when you put it up. :) Other than that, cool job, I approved it for ya. :nod:

And BW, sweet use of what's already there. I love it. :nod::yes:
Title: Gravity - with (I hope) very minor code changes.
Post by: karajorma on June 14, 2004, 02:56:58 pm
This is nice. :D

I'm glad to see people coming up with new uses for the extra SEXPs in FRED. As people get more and more familiar with them we're going to see more and more formerly impossible things done in campaigns :D

Plus it shows Goober that his SEXPing work is valued and encourages him to do more :D
Title: Gravity - with (I hope) very minor code changes.
Post by: WMCoolmon on June 14, 2004, 05:35:12 pm
What happens when you dock to a support ship?

Edit: NM
Title: Gravity - with (I hope) very minor code changes.
Post by: LtNarol on June 14, 2004, 09:59:24 pm
w00t!  Now all we need is a tank AI and roll limitations :D
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on June 14, 2004, 10:15:41 pm
This is news? :nervous:

Quote
Originally posted by Lightspeed
BlackWolf:

I just had an idea. It should be possible to have the drop-down distance increased over time if it used another variable.

You could change the gravitation drop down according to the speed of your vessel, and according to its Y position.

 


This is interesting, but it doesn't really simulate the way gravity works in the distances we'd be talking about (ie. between 0 and, say, 10000 m on average ASL). If we set it up this way, stoppping a few meters above sea level would see you slam into the ground at some ridiculous speed... but there might be a way to adapt it so that you do fall a variable defined distance based onthe time since the fall started - if we could get FRED to trigger a flag every time the evnt statrs, but not when it repeats - that might be a bit more challenging...

Quote
Originally posted by aldo_14
NB: I was working on an atmospheric mod till recently, but dumped it because of the whole gravity thing (specifically, the debris).


 Yeah, we thought about this. Chances are we'll just be using a lot of ship vaporize sexps to eliminate the debris, or just not putting debris on the atmospheric-only pofs we use.

Quote
Originally posted by HotSnoJ
If we know the mission 'world's' X, Y, and Z coordinates, why couldn't something like this be coded into the engine long ago? [/idiot talk]


Presumably because until recently the infrastructure for atmospheric flight wasn't available. The decent stuff's only really come along with the advent of skyboxes and HTL, allowing the higher poly models we need (Though, for the record, the reason TIs atmospheric stuff takes place over water was originally so we could get it working without HTL). Also, the get position sexps are SCP additions, and as Karajorma's touched on, a lot of the new sexps haven't been exploited to their full potential as yet.

Quote
Originally posted by LtNarol
w00t! Now all we need is a tank AI and roll limitations


Read your public forum whydonchya? :p VA sorted this one (roll limitations) out awhile back. We're using it for boats, but it'll apply just as well to your stuff.
Title: Gravity - with (I hope) very minor code changes.
Post by: Solatar on June 15, 2004, 01:33:36 am
It might be tedious to do for every ship, but for major ships in a battle, after they are destroyed you could no-warp-effect in a damaged model and have it's first orders be to plumit toward the ground. When it hits you add a nice explosion. That way if you have any capital ships or whatnot in the area, they don't just disappear.
Title: Gravity - with (I hope) very minor code changes.
Post by: karajorma on June 15, 2004, 05:21:20 am
Quote
Originally posted by Black Wolf
This is news? :nervous:


I don't know if it's big news but basically you do deserve credit for solving one of the big FS2 impossibles :D

Quote
Originally posted by Black Wolf
This is interesting, but it doesn't really simulate the way gravity works in the distances we'd be talking about (ie. between 0 and, say, 10000 m on average ASL). If we set it up this way, stoppping a few meters above sea level would see you slam into the ground at some ridiculous speed... but there might be a way to adapt it so that you do fall a variable defined distance based onthe time since the fall started - if we could get FRED to trigger a flag every time the evnt statrs, but not when it repeats - that might be a bit more challenging...


I agree but that doesn't mean you can't use this for micro black holes or gravitic weapons. :D Either of those could a much smaller fall off distance.
Title: Gravity - with (I hope) very minor code changes.
Post by: Lightspeed on June 15, 2004, 05:44:21 am
Quote
Originally posted by Black Wolf
This is interesting, but it doesn't really simulate the way gravity works in the distances we'd be talking about (ie. between 0 and, say, 10000 m on average ASL). If we set it up this way, stoppping a few meters above sea level would see you slam into the ground at some ridiculous speed... but there might be a way to adapt it so that you do fall a variable defined distance based onthe time since the fall started - if we could get FRED to trigger a flag every time the evnt statrs, but not when it repeats - that might be a bit more challenging...


I know, that would be ideal. But I think if you apply a good multiplayer my system would work well enough. (You'll need to use a logarithmic approach to the problem)
Title: Gravity - with (I hope) very minor code changes.
Post by: Goober5000 on June 15, 2004, 08:26:05 am
Wow, excellent work, Black Wolf. :) As karajorma said, I'm certainly glad to see people doing new stuff with the sexps. :nod:

I have two suggestions
1) Try using every-time in place of when.  I think it's coded to evaluate every frame.
2) As you know, gravity is proportional to the square of the distance, so maybe you could try something like this:
Code: [Select]
every-time
  true
  set-position
    Alpha 1
    get-position-x
      Alpha 1
    -
      get-position-y
        Alpha 1
        *
          5
          distance
            Alpha 1
            Planet
          distance
            Alpha 1
            Planet
    get-position-z

3) Have you tried firing an invisible beam with a negative force to simulate gravity?  It might be the smoothest current solution.
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on June 15, 2004, 09:51:13 am
Not in the current setup, but I have experimented with negative mass tractor beams in the past. Never got them to work unfortunately.

The problem is a that our planets are actually flat planes rather than points, though we could use Get position Y again. Still, it runs into the same problem as lightspeeds - your speed would depend on your position, rather than the amount of time you'd spent falling. We probably will have to apply some sort of meethod like this, but I want to see if I can fiddle something with flag setting first - maybe change a variable every time your speed drops below X, and then setting up the change based on one of the time sexps. It's not likely going to work, but it'll be worth a try anyway.

BTW, I don;t think I have every-time on FRED - I'm assuming it's under conditionals with when? I just got sent a whole bunch of FSO related stuff in the mail though (Thanks Xelion!) so I may have a more recent version on disk somewhere to test that with.

Quote
Originally posted by karajorma


I don't know if it's big news but basically you do deserve credit for solving one of the big FS2 impossibles :D
 


It's not solved yet... *Points SCPers in direction of first post*

:nervous:
Title: Gravity - with (I hope) very minor code changes.
Post by: karajorma on June 15, 2004, 10:23:39 am
Didn't realise the every-time SEXP had been committed yet. :D

I assume it's in the bob birthday build of FRED?

I'm going to have to do some experimenting tonight :)

BW: While it might not be solved, it's a major step towards having it work :)
Title: Gravity - with (I hope) very minor code changes.
Post by: Lightspeed on June 15, 2004, 10:48:58 am
It does indeed rely on position rather than time you have been falling BUT it's at least a better fake then just applying the same thing everywhere :)
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on June 15, 2004, 10:59:42 am
Agreed, but the problem is that most of TIs fighting will be taking place close to ground level, and crashing into the ocean will be fatal. This is going to add a fair bit of challenge to the mission as it is, but I don;t want to make it insurmountable.

NB - for something like the 158th, where a lot of their missions would (I assume, based on their screenies) take place in the upper atmosphere, where the player isn't supposed to be mucking around down near the ground, it'd work well, and could probably be adapted fairly easily. But for the moment, I need a system that'll work for TI, so I want to spend at least a little while longer researching stuff before I settle down on anything. Keep in mind that the method I develop will not neccesarily have to be the method everyone uses.
Title: Gravity - with (I hope) very minor code changes.
Post by: Lightspeed on June 15, 2004, 11:38:41 am
Thats why you should keep it to low multipliers. :)
Title: Gravity - with (I hope) very minor code changes.
Post by: WMCoolmon on June 15, 2004, 04:16:23 pm
Updated FS2 and FRED (http://www.hard-light.net/forums/index.php/topic,24223.0.html)

Has current-speed in it.
Title: Gravity - with (I hope) very minor code changes.
Post by: Goober5000 on June 15, 2004, 04:33:13 pm
Quote
Originally posted by Black Wolf
BTW, I don;t think I have every-time on FRED - I'm assuming it's under conditionals with when?
Yes, but it's not in FRED yet.  It's in 3.6, though.  Just change "when" to "every-time" using Notepad.

I'll take a look at doing actual gravity.  I think it'll be pretty straightforward to implement.
Title: Gravity - with (I hope) very minor code changes.
Post by: Flaser on June 15, 2004, 04:58:26 pm
IMHO a simple constant acceleration for all ships would be enough to simulate gravity itself, since no atmospheric battle will take on speeds or heights where change of gravity is significant.

However, the lift - or the prolusion system that keeps an aircraft or aerospacecraft in the air would be more difficult to implement.

You need to take into account the position of the wings or elevating surfaces. The easiest solution I can think of is aplying an acceleration normal to those surfaces at all times - however the ammoun should be some function that uses current velocity.

The mission designer should be able to set the ammount of gravity, an individual factor of speed dependant lift for all crafts, as well a constant lift factor to simulate hovercrafts.
Title: Gravity - with (I hope) very minor code changes.
Post by: Trivial Psychic on June 15, 2004, 09:32:46 pm
If we do try to factor in lift for atmospheric flight in a gravitational environment, perhaps each ship should have a lift factor in its table entry.  The degree of lift would of course have to change depending on what angle the ship is to the gravitation source.  Perhaps the lift could be coded to be like a thruster on the underside of each lift-capable ship, so you wouldn't get lift in a dive that pushes you away from the gravitational source.  Also, the lift factor would also change depending on the actual speed of the craft.  I was going to say that the thruster would be tied into the main throttle, so that if you cut your speed, you lose your lift, but that eliminates gliding... so it would need to be tied to the ship's actual speed.

I'm not sure if that makes complete sense... but there it is.

Later!
Title: Gravity - with (I hope) very minor code changes.
Post by: WMCoolmon on June 15, 2004, 10:04:36 pm
FS2 ships can slide up/down/left/right if configured, yes?

So, implement a command that toggles auto-firing thrusters to keep the ship level; this would include the main drive.

Ex: Johnny Bravo enters the mission area in his custom hoverbike, configured to auto-thrust. Without touching the controls, the craft simply floats at a speed of 0, while the bottom thrusters fire at 50%.

Then the Penguin fires a large bullet. Johnny dodges by moving upwards; the craft's bottom thrusters jump to 100% as he presses the "slide up" key, then drop back down to 50%.

The penguin fires another projectile, this time Johnny slides down; the bottom thrusters disengage and the top thrusters fire at 100%.

Johnny decides to fly away from the planet as fast as he can, so he turns his ship so its rear faces the planet. The bottom thrusters again disengage, and this time the main engines auto-thrust at 25%. Johnny hits the full-throttle button and the main engines engage at 100%.
Title: Gravity - with (I hope) very minor code changes.
Post by: ShadowWolf_IH on June 22, 2004, 12:00:23 pm
why not reset the interval to ms instead of seconds, it would make for a much smoother transition on things like this.  besides, the send message list runs off of ms.

It would make things look alot less jerky
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on June 22, 2004, 01:14:53 pm
But it would also destroy any events using the current repeat system. By decreasing the permitted interval, we can get the same effect without breaking anything.
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on July 06, 2004, 10:37:52 pm
Bumpo.

Don;t waqnna let this one go that easily :)
Title: Gravity - with (I hope) very minor code changes.
Post by: Flipside on July 08, 2004, 11:51:02 am
It's a bit tough because no FS2 ships can really get up enough speed to stay airborne. You really need 2 values for speed 'physical' and 'absolute y', physical being what is shown on the HUD and absolute being the vessels absolute y velocity (I don't remember the maths, but it invloves a triangle of the physical speed, and time taken for measurement, and the opposite will be the absolute Y velocity iirc.)

If you could find a way of affecting the ships absolute y velocity decreasing it using a multiplier, you could have a gravity effect that works, at least for the way TI does it, it could give the 'wheelie' effect when a ship reaches it's ceiling, of the nose pointing up, but the ship not climbing.

That idea would take source code changes though :(
Title: Gravity - with (I hope) very minor code changes.
Post by: Goober5000 on July 08, 2004, 12:27:49 pm
I think I know how you might do this.

Make a system, like the one for adding waypoints, that would add "gravity points".  Each point would have a characteristic acceleration affecting all objects in the area.  You might get some cool effects if you put a bunch of those in an asteroid field. :p

For atmospheric missions, we might specify "lift" on a ship-by-ship basis that would either counteract or reinforce the gravity.
Title: Gravity - with (I hope) very minor code changes.
Post by: kasperl on July 08, 2004, 12:34:11 pm
Goob: Perhaps a mission flag with lift multiplier. This way you could make a difference between flying in Jupiter and flying on an Earth like atmosphere.
Title: Gravity - with (I hope) very minor code changes.
Post by: Goober5000 on July 08, 2004, 03:38:05 pm
Different atmospheric lift... good idea.  Though from an air-resistance perspective, I'd think you'd want different plane designs in different atmospheres.
Title: Gravity - with (I hope) very minor code changes.
Post by: Flipside on July 08, 2004, 03:46:32 pm
Hmmmmm.....Now, if you could set a random 'turbulence' plane, you could kill two if TI's birds with one stone ;)
Title: Gravity - with (I hope) very minor code changes.
Post by: Goober5000 on July 08, 2004, 04:01:22 pm
You can do that already.  Just set off explosions at random locations using the explosion-effect sexp.  Set the damage to 0 and use varying blasts, and there you have it. :)
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on July 09, 2004, 02:07:52 am
All of this is very (very ;)) interesting, but it all strikes me as sort of step two stuff. Could you check about decreasing the repeat interval before you get into this more complex stuff? I don't want to come across as overbearing, but I also don't want to see the issue get overcomplicated before even the most basic changes get made.
Title: Gravity - with (I hope) very minor code changes.
Post by: Goober5000 on July 09, 2004, 09:44:24 am
Why can't you use the every-time sexp?  It's in 3.6.
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on July 09, 2004, 11:17:27 am
Oh... doh - ignore me. I'll be grabbing 3.6 as soon as I go back home, but since I don't have it yet, I haven't been able to try that, and completely forgot about it . :nervous:

My mistake, carry on...:nervous:
Title: Gravity - with (I hope) very minor code changes.
Post by: Black Wolf on August 12, 2004, 10:03:23 pm
BaBump.

OK, finally got around to upgrading my version of the SCP and tested - every-time takes away the joltyness, but one thing I didn't anticipate is that this method doesn't handle collisions very well, so unless there's an easy way around that, the method's effectvely useless :(