Need help with my game physics...

Blitz3D Forums/Blitz3D Programming/Need help with my game physics...

OrcSlayer(Posted 2005) [#1]
I think I asked about this once, but now I know better what I need so I'll ask again.

I need someone, preferably with some experience in this area, to help me with the physics for my game engine. I want to have a simple system, similar to older games (Marathon, Unreal, Quake, etc), which features inertia transfer and basic bouncing physics. I would also like some more realistic gravity than the oh-so-common "TranslateEntity,0,-2,0" approch, one that actually makes you fall faster the longer you're airborn (I'll be using the players fall speed to inflict damage when they land). I've done some expirements with it and have a basic understanding of implementing gravity, but I am just not that good at detecting if the player is on the ground or not...very fuzzy results in my early tests.

As far as inertia transfer goes, I think I have an idea how to do it, except I have one major problem. Currently I use MoveEntity, since it's the only way I know how to accurately move an object. For inertia transfer to work, I understand it's best to use TranslateEntity commands to move characters around, but I don't know how to get the X and Z amounts to translate by based on the objects rotation.

If someone would be willing to offer some assistance in these areas, feel free to contact me for more information on the game project. It will be a semi-commercial release, so I am willing to pay for someone to fill this "Assistant Coder" position.


Damien Sturdy(Posted 2005) [#2]
[/quote]that actually makes you fall faster the longer you're airborn (I'll be using the players fall speed to inflict damage when they land).
[/quote]

yspeed=yspeed-1
Moveentity Player,0,yspeed,0
if entityy(player)<0 then yspeed=0:if keyhit(57) then yspeed=30



_PJ_(Posted 2005) [#3]
Substitute the '-1' above for an Acceleration-Due-To-Gravity value based on whatever units fit your gameworld.

The SI value 'g' varies slightly due to the oblateness of the earth and the value changes from 9.789 to 9.823 ms-2 (where the higher value reflects a polar 'g' and the lower value would be equatorial.)

Use TranslateEntity just for gravity, because Gravity always acts Globally downwards, but of course, use MoveEntity for general control and movement because this will be relatively Local.


Damien Sturdy(Posted 2005) [#4]
Whoops, My bad ^.^ Was just throwing code about there anyway.

So, change the code above so instead of moveentity, it reads Translateentity.


OrcSlayer(Posted 2005) [#5]
Well, that's pretty much what I had figured out...but there are some other problems (like not continuing to accelerate if the entity is on the ground...since y velocity on impact will cause damage you can't be walking around with a constantly growing negative amount of y velocity). I know linepick is what is generally used to detect if the player is on the ground or not, but I am not very good at setting up linepicks I guess since it never works for me.

And as I stated on the subject of MoveEntity, my point is I am planning on inertia transfer and thus I need to use TranslateEntity, I just need to know how to get the appropriate values based on object rotation to apply "thrust." Unless there is an easier way to do inertia transfer, but nobody has told me of one so far...


Damien Sturdy(Posted 2005) [#6]
in this case:
if entityy(player)<0 then yspeed=0:if keyhit(57) then yspeed=30


could be

dmg=0
if countcollisions(player)>0 then dmg=yspeed:yspeed=0
dmg=dmg-2:if dmg>0 then energy=energy-dmg


note that what i just typed is very rough and just an idea for you. i used it in Den Bros 4.

Now, thrust.
the way i used to do it:

store layers current position
MOVEENTITY player,0,0,1
compare this position to the last position. store.
moveentity player,0,0,-1

Add the compared values to your current motion.

I now use TformPoint... look that up and itl be much faster than the above and much cleaner too. I dont know how i survived without that command!


Rob Farley(Posted 2005) [#7]
Here's a Physics for beginners example I posted a while back.




OrcSlayer(Posted 2005) [#8]
Ok, starting to get somewhere now! Rob seems to have some good bounce/gravity physics, will certainly come in handy. And, Cygnus, you said TFormPoint...someone told me that's what I needed to use to get the amount of thrust a while ago, but never explained it. I looked at it in the command reference (again) and it's just as cryptic to me as it was before. If you could give me an example of how to use it to get the results I'm after, I would be very grateful.


Damien Sturdy(Posted 2005) [#9]
Well, I'm still prettu new to it but here i go (im not at home so if i get something wrog, someone correct me ;))

Tformpoint x#,y#,z#,Source_entity,Dest_entity

So:

Player=createcube()
Tformpoint 0,0,1,player,0


this will put the equivalent values into tformedx(),y() and z() of donig ths same as moveing the entity forward by 1, and getting the position. However, the object does not move.


i find this hard to explain.. could someone help out here?


OrcSlayer(Posted 2005) [#10]
Ok, let me see if I understand this properly...

Doing

TFormPoint,0,0,1,player,0

and then

TranslateEntity,player,TFormedX,gravity,TFormedZ

Would result in the same thing as

MoveEntity,player,0,0,1
(and a seperate TranslateEntity,player,0,gravity,0 of course)

but in a way I could apply external force more easily...

I'll have to try this out as soon as I get my project files sorted out (backing up stuff for reformatting sucks)...I just looked and Sswift suggested using TFormVector in this way, but I didn't quite understand at the time. The two seem identical except, well, one works with a point and one works with a vector...not sure quite what that means to me and you...but...


Rob Farley(Posted 2005) [#11]
To apply external forces personally I create a physics pivot...

I posted an example of this here

http://www.blitzbasic.com/Community/posts.php?topic=42358#474859


OrcSlayer(Posted 2005) [#12]
Very interesting...nice cheat there Rob. Will definately try that out. Anyone who has played an action game knows how visually pleasing it is to bounce objects around with explosives and big guns...even if the physics aren't 100% accurate newtonian.