Verlet Physics engine 2

Blitz3D Forums/Blitz3D Beginners Area/Verlet Physics engine 2

Nate the Great(Posted 2008) [#1]
Hi this is a continuation of my previous physics thread because it was too long and took forever to load.

Here is my most recent code you still need heightmap1.bmp posted at the bottom





Here is the link to heightmap1.bmp
http://files.filefront.com/heightmap1bmp/;11773113;/fileinfo.html


GIB3D(Posted 2008) [#2]
I tried that with the second UpdateWorld() taken out and it works the same, I don't see why you would need two. I get a tiny bit faster FPS too. But if you need it then don't mind me XD.

But anyways.. I like how it's going. It may be slow but at least it works. Hopefully you can get it to go faster and be as great as Half-Life 2 physics (or better).


Nate the Great(Posted 2008) [#3]
Oh Thanks for pointing that out I just forgot to take it out. When I finish it, I will make an updatePhysics function that also updates the world and all of the physics.


Nate the Great(Posted 2008) [#4]
I am having a problem with applying rotational velocity to things here is the code. The function that doesn't work is the last one.




Here is the function I am having trouble with

Function PApplyRotationalVelocity(Ent,axel,Yaw#,pitch#,roll#)

tmpPiv = CreatePivot()

PositionEntity tmppiv,EntityX(axel),EntityY(axel),EntityZ(axel)

TurnEntity tmppiv,EntityYaw(axel),EntityPitch(axel),EntityRoll(axel)

For V.verlet = Each verlet
	If V\ent = ent Then
		EntityParent v\piv2,tmppiv
		PositionEntity v\piv,v\x#,v\y#,v\z#
	EndIf
Next

TurnEntity tmppiv,-Yaw#,-Pitch#,-Roll#

For V.verlet = Each verlet
	If v\ent = ent Then
		V\ox# = V\ox# + (v\x# - EntityX#(v\piv2))
		V\oy# = V\oy# + (v\y# - EntityY#(v\piv2))
		V\oz# = V\oz# + (v\z# - EntityZ#(v\piv2))
	EndIf
Next

TurnEntity tmppiv,Yaw#,Pitch,Roll#

For V.verlet = Each verlet
	If v\ent = ent Then
		
		;EntityParent v\piv2,0
		FreeEntity v\piv2
		v\piv2 = CreatePivot()
		;RotateEntity v\piv2,0,0,0
		;PositionEntity v\piv2,V\x#,v\y#,v\z#
	EndIf
Next

FreeEntity tmppiv
End Function




Does anyone know how I could apply rotational velocity correctly? This doesn't seem to work.


Stevie G(Posted 2008) [#5]
Rotation for verlet is best done by applying forces/acceleration to the pointmasses / verlets. Your system does not do this it only uses implied velocities. You are therefore missing acceleration and a timestep constant in your code.

ImpliedVelocityX# = ( CurrentXPos - OldXPos ) * Damping + AccelerationX * TIMESTEP ^ 2

ImpliedVelocityY# = ( CurrentYPos - OldYPos ) * Damping + AccelerationY * TIMESTEP ^ 2

I'm not sure what you are trying to do in your function above but it is not very efficient to iterated through every verlet just to find the ones you want. Either use a linked list of verlets or create a blitz array to hold your verlets within the rigidbody type. I've already mentioned this. Also, don't keep freeing and creating pivots. Create one GLOBAL helper pivot and re-use it.

If you look at this paper then it explains the best way of setting things up correctly.


accumulate forces -----> update verlets -----> reset forces ------> update constraints ( including collisions )



http://www.gamasutra.com/resource_guide/20030121/jacobson_01.shtml

Taking a 2d example :

Imagine this simple object

p1-----------p2


Where p1 & p2 are pointmasses ( verlets ) with the line being a constraint connecting them.

To rotate this object clockwise you apply an upwards force to p1 and a downwards force to p2. Both forces should be equal but opposite for s mooth turn. Note that getting the object to rotate to a specific angle isn't so easy but can be simulated by reducing the force applied the closer it gets to the target and also applying friction forces perpendicular to the movement.

                    |
                    V
p1-----------p2
^
|


I'd recommend you get the basics right in 2d before moving to 3d. Note that this doesn't stop you from using 2d in 3d to make use of blitz collisions. You simply have to ignore the z axis.

Hope this helps you.

Stevie


Nate the Great(Posted 2008) [#6]
As always You have been a lot of help stevie thanks

I realize that it is inefficient however I don't know what you mean by create a list of verlets or how to make a blitz array that is different for each rigidbody. I am not sure how to do these things exactly.

I am also confused about exactly what a timestep is.

Sorry if the answers to my questions seem obvious but I don't know everything about B3d yet.


Stevie G(Posted 2008) [#7]
Within a type, a blitz array must be set to a maximum per rigid body, it's doubtful you should get past 50 pointmasses with such a simple system. For linked lists use the search function - it's been asked many times before.

Read the article - the timestep is just a constant which tells the system how many times to update accelerations per second. I tend to use 0.05 in conjunction with high gravity of 40ms-2

This might sound harsh but if you are a beginner with the language then starting with a physics engine is probably not a good idea.


Nate the Great(Posted 2008) [#8]
I'm not a real beginner. I have programmed for 5 years. I just now started getting on the blog though and have started learning a lot of things that I could not find in the help section of b3d. I will try out the array thing for now. Thanks :)

Also I found a fun little bug in polymaniacs after a few hours of playing. If you are using a tank on keys 2 after the game over thingy starts to come in you can press self destruct over and over an you will fly in the air like a helicopter. sorry I couldn't post a video but it is really funny seeing a tank fly in a game.


Stevie G(Posted 2008) [#9]

Also I found a fun little bug in polymaniacs after a few hours of playing. If you are using a tank on keys 2 after the game over thingy starts to come in you can press self destruct over and over an you will fly in the air like a helicopter. sorry I couldn't post a video but it is really funny seeing a tank fly in a game.



Which mini-game? I knew this happened in Timetrial as you're indestructable there. This is all fixed now though - you can't shoot or self-destruct when the game is over and in timetrial it resets you to the start position.


Nate the Great(Posted 2008) [#10]
You can self destruct at the end of deathmatch when the game over thing still hasn't grown to its full size.

Just wanted to mention. Someone saw me playing polymaniacs over my shoulder at school and wanted to play so now almost every guy at my school has it on their laptop. I think you would make a ton of money off of this game considering it is so populare at my school.

P.S. How many different worlds are you planning to have in your final game. 3 worlds is fun but more worlds would mean more fun. :)


Pongo(Posted 2008) [#11]

P.S. How many different worlds are you planning to have in your final game. 3 worlds is fun but more worlds would mean more fun. :)



Just wait until you see the..... nahhh, I'll let Stevie tell you! :)


Nate the Great(Posted 2008) [#12]
What are you talking about pongo???

P.S. How is the physics coming?


Stevie G(Posted 2008) [#13]

P.S. How many different worlds are you planning to have in your final game. 3 worlds is fun but more worlds would mean more fun. :)



There will be loads of levels with alot more variation. Here's a quick preview of a prototype stunt level Pongo has been kindly building for me .. fantastic fun :)




Just wanted to mention. Someone saw me playing polymaniacs over my shoulder at school and wanted to play so now almost every guy at my school has it on their laptop. I think you would make a ton of money off of this game considering it is so populare at my school.



Thanks - that's good to know. I'm not convinced yet about making much money - we'll see though.


Nate the Great(Posted 2008) [#14]
[quote]There will be loads of levels with alot more variation. Here's a quick preview of a prototype stunt level Pongo has been kindly building for me .. fantastic fun :)[\quote]

Is there a level builder or something?

That level looks fun :)


Stevie G(Posted 2008) [#15]
There is a level builder but it isn't very user friendly at the moment. I hope to integrate it into the game but we'll see how that goes.


Nate the Great(Posted 2008) [#16]
ok Feel free to email it to me if you want me to make a level :) I don't mind if it isn't user friendly

I think it would be a nice effect to make the water like ice when it was snowing. :)


Stevie G(Posted 2008) [#17]

I think it would be a nice effect to make the water like ice when it was snowing. :)



This is easily done so I will add it at some point.

Anyway, I've hogged this thread enough ...


Nate the Great(Posted 2008) [#18]
I think after I tweak some things and make them more efficient I will leave my physics engine simple and pretty close to how it is so I can adopt it to almost any game I want to make and make it efficient for that game.

this has been a very fun project... so far :)

BTW How do you use seperating axis theory? I don't get how to use it?


Nate the Great(Posted 2008) [#19]
Here is my code so far. I'm not sure that I will take this any furthur until I figure out what kind of game I will need it for. :)




I was surprised that it is still very stable if you set the number of times in the constraint loop to 3


Nate the Great(Posted 2008) [#20]
Here is a fun little demonstration of my physics engine

No terrain map required for this one. :)




Nate the Great(Posted 2008) [#21]
hmm...

I probably should have put this in the blitz3d programming section rather than the b3d begginers area because it isn't really a beginner's topic but it is too late now. :(


GIB3D(Posted 2008) [#22]
yay it's awesome!


Nate the Great(Posted 2008) [#23]
How would I make constraints to constrain the wheels to the car? This is very confusing.


Nate the Great(Posted 2008) [#24]
Stevie on average how many verlets do you have per vehicle? I can't see each vehicle having a verlet for every vertex. Do you have 4 big verlets for each wheel or what?

P.S. I put my code in the code archives and gave you and pongo credit. :)


Gabriel(Posted 2008) [#25]
This is nice. I was pleasantly surprised considering you haven't been working on it all that long. I eventually managed to get the puck out of the constraining box too. ( I don't mean an error, it didn't go through the wall. I managed to get it moving fast enough that it bounced up and over. )


Nate the Great(Posted 2008) [#26]
It is fun to play around with. If you change the createpivot to create sphere in the funciton create verlet, then you can see the verlets reacting with each other.

I plan to start making a game using it soon although it might be a few years before I get a demo out :)

P.S. This has been a very good learning experience for me. Thanks pongo and Stevie G!!! Good luck with polymaniacs can't wait to buy it :)