Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm programming a throw of 5 dices in Actionscript 3 + AwayPhysics (BulletPhysics port).

I had a lot of fun tweaking frictions, masses etc. and in the end I found best results with more physics ticks per frame. Currently I use 10 ticks per frame (1/60 s) and it's OK, though I see a difference in plus for 20 ticks.

Even though it's only 5 cubes (dices) in a box (or a floor with 3 walls really) I can't simulate 20 ticks in a frame and keep FPS at 60 on a medium-aged PC. That's why I decided to precompute frames for animation, finishing it in around 1700 ticks in 2 seconds. The flash player is freezed for these 2 seconds, and I'm afraid that this result will be more of a 5 seconds or even more, if I'll simulate multi-threading and compute frames in background of some other heavy processes and CPU drawing (dices is only a part of this game).

Because I want both players to see dices roll in same way, I can't compute physics when having free resources, and build a buffer for at least one throw of each type (where type is number of dices thrown). I'm afraid players will see a "preparing dices........." message too often and for too long.

I think the only solution to this problem is replacing PhysicsEngine with something simpler, or creating own physicsEngine. Do You have any formulas for cube-cube and cube-wall collision detection, and for calculating how their angular and linear velocities should change after a collision occurs?

Edit: I'm assuming the only way to solve my problem is to make a cube-cube and cube-wall collision engine, however maybe there's another solution for my problem.

  • As Arthur pointer out, there can be one animation - for me this is just a shortcut, I could as well show the final result without any dices rolling.
  • However, I thought about making 100 precomputed dice throws, though a user won't avoid repetition here as well. Sometimes a dice sits on it's edge (or corner) for a while, and that gives player some excitement (will it fall on 5 and give me a full house?), but with limited number of animations a player would already know how the animation will end.
  • Buffering solution would work, if players would see dices roll in different way (results would still be the same) - I'm considering this solution, however I'm still going to try to create a simple physics engine and see how it works.
  • less ticks is a solution I don't consider, because at as few ticks to be able to simulate physics in real-time, the dices behave not better than if I treated them as balls in my physics engine...
share|improve this question
    
1. Your idea of investing time in re-creating a 3d engine is not a great one to say the least. Why do you think the new engine will preform better than the existing one?(that people already invested many months in developing) 2. Is it so important to simulate the dice rolling physics instead of having a saved-up animation (like many other games). As a player I do not see how that would affect my desire to play a game. I honestly think you might be procrastinating from other goals that will lead to the completion of the game. imho –  Zehelvion Oct 1 '12 at 15:27
    
Basically, the simple and fast dice physics are the ones provided by the engine when you set the tick count to a low number. There are no 'simple' solutions to most physics simulation problems because the collisions are not discrete (they happen between frames) and sometimes could lead to more collisions, the number could easily get very large when many bodies are near one another. –  Zehelvion Oct 1 '12 at 15:37
    
1. There are 2D physics engines that are way slower then my own 2D physics engine I made for one of my games. The thing is I knew that in my game there will be points colliding with triangles of right angles. When making a universal 2D engine you need universal methods of collision-detection, and for this universality you pay a price of weak performance. 2. Yes, it is important, look at the Witcher game - it would be so pathetic if CDPRed made only one animation of the dices. Dice throwing will be one of main parts of my game. 3. With a low tick-to-frame ratio, dices get much too bouncy. –  Markus von Broady Oct 1 '12 at 16:06
    
So why not simply save 50 different dice roll animations in advance which you can can show from 360 * 360 random camera angles and be done with it. –  Zehelvion Oct 1 '12 at 16:14
    
@ArthurWulfWhite The more animations I create, the less repeatability, but more size of the SWF file. We're talking about 170 frames * 5 dices * (3 rotations + 3 positions ) * 32 bit for an int = 20 kB per animation. 50 animations will take 1 megabyte! –  Markus von Broady Oct 1 '12 at 16:26

1 Answer 1

You could use FlasCC to optimize performance for 3d physics and rendering. Go here: http://gaming.adobe.com/technologies/flascc/

They have an example of flascc with bullet physics. I think using it should increase performance dramatically. Give it a shot.

share|improve this answer
    
UDK has better physics engine than BulletPhysics? (especially in regards to simple meshes) –  Markus von Broady Oct 9 '12 at 8:44
    
I suggest we benchmark this? It sounds promising. –  Zehelvion Oct 9 '12 at 8:47
    
I'll look into for sure, thanks. –  Markus von Broady Oct 9 '12 at 8:51
    
Try messing around with pure UDK to get a good estimate. I will do the same and update with my findings later this week. –  Zehelvion Oct 9 '12 at 10:16
    
I found something interesting in the FlasCC notes: "new Away3D + Bullet physics example". Edited the answer accordingly. –  Zehelvion Oct 13 '12 at 10:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.