Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: AndrewofDoom on July 21, 2012, 12:51:26 pm
-
So currently I'm having an issue with an dealing with ship-ship collisions in my super cool awesome rad mod I've been working on. Every time the player touches a ship, he'll skid along the surface. I know why this is happening. It's every frame I add to the player's velocity an equivalence speed to what the camera is scrolling at. Pretty scarey equation too to make it work. Take a look if you dare. (https://dl.dropbox.com/u/17350885/UglyEquation.png)
"So, Andrew, why exactly are you doing this?"
Why? I rather not do this to be honest, but certain...silliness about how FSO does collision detection. Originally, I had just moved the player's position every frame at the same rate as the axes scroll rates (everything else except the player that is slaved to the scrolling still does this actually). The issue comes when the player sits still and he is scrolled into a ship. Since neither the player or the ship he's about to run into do really have an actual velocity, the engine knows none of the better and pretends they aren't even intersecting, leading to ALPHA ONE becoming ETHEREAL ALPHA ONE.
Right, so enough rambling, I need some coming up with a way to deal with ship-ship collisions without causing the player to skid forward, become ethereal and noclip through the sucker, or as you'll see in the script I show down below, the player gets hurled forward moments later. This is the last physics issue I have that is wrt my script I made.
Here's the whole script. (http://pastebin.com/3jLEcr1e) This one is an updated revision to fixes some other issues such as weapons and player being blocked by exploding ships. The speed adjustment related stuff begins on line 138 and ends with the Simulation hook.
I personally see only two options:
- Rewrite how collsion detection works. Like hell I can do that.
- Reduce the player hitbox for ship-ship collsions and kill the player instantly if he does collide. Because, hell, you'll be dead in levels where it is claustrophobic anyway.
I rather not do the second option, and I lack the skills to take on the first option.
-
Egad, you're doing everything by setting the position directly! Just use velocities instead and collision detection should work fine... or is that what you were doing when it was 'skidding'?
Or is my "just use velocities" assuming you're much better at math than you actually are?
-
Setting velocities results in collision skidding (it is really stupid - colliding itself works fine, it's what happens after)
Setting position results in no collision under certain circumstances.
-
my problem with scripting a replacement physics engine for freespace is that there was no way that i knew of to turn off stock physics simulation. these days you can kinda hook into collision response now to do stuff, but you really cant turn off the stock response either. the game also has some new hard coded physics options, but these are likely to be just as limiting. this engine really isnt suited to a newtonian framework anyway so realistic physics are not possible. but you can kinda fudge it to make it satisfactory.
collision detection requires at least a frame's worth of physics state data history. why i exposed old velocity and old position (i think old orientation as well) to scripting. still that doesnt help much because you can set the velocity but fs is going to change it next time it runs its simulation code. you have to find a hook that runs right after that but before collision detection so you can replace freespace's values with your own. im not sure if such a hook exists.
my solution to the problem was to code a new game engine in lua standalone and port my physics scripts over (ive yet to do the latter and the former needs work). :D
-
The typical 'helpful' replies I see here!
-
collision detection requires at least a frame's worth of physics state data history. why i exposed old velocity and old position (i think old orientation as well) to scripting. still that doesnt help much because you can set the velocity but fs is going to change it next time it runs its simulation code. you have to find a hook that runs right after that but before collision detection so you can replace freespace's values with your own. im not sure if such a hook exists.
Actually this part could be kinda helpful
-
i was more or less sharing my experience with physics mods. i eventually got stumped and gave up. thats not really all that helpful. i think i actually managed to get my ships and weapons to behave like i wanted, and the thing which ultimately doomed it was crashes on weapon impacts. i was simply pushing beyond the capabilities of freespace's numerical stability. you may want to poke through the atmospheric scripts there to see if you get any ideas.
-
Couldn't you just not add the scroll rate to the player when it's in contact with another ship?
-
Couldn't you just not add the scroll rate to the player when it's in contact with another ship?
That might work... but it would have to be re-enabled when the player craft starts going off-screen. :P