JigLib engine - forcing ball to move

Software: Away3D 4.x

Gugis, Newbie
Posted: 12 July 2012 01:54 PM   Total Posts: 6

I’m making billiard game with Away3D and JigLib engine. I use command addWorldForce to force cue ball moving:

cue.addWorldForce(new Vector3D(5000), cue.currentState.position); 

Ball is moving but it lasts eternity until cue ball stops moving. Velocity is falling-off very slowly. Here’s velocity trace log:

Vector3D(3.3099512757763256, -3.7111515419892314, 0)
Vector3D(3.3066413245005495, -2.6185628029613723, 0)
Vector3D(3.303334683176049, -0.00016308234093761697, 0)
Vector3D(3.300031348492873, -0.00010980444487101516, 0)
Vector3D(3.29673131714438, -0.00012081260197683408, 0)
Vector3D(3.2934345858272356, -0.00017622854164007462, 0)
Vector3D(3.2901411512414085, -0.00013069730750039365, 0)
Vector3D(3.286851010090167, -0.00008521160459511545, 0)
Vector3D(3.283564159080077, -0.00014299974510101164, 0)
Vector3D(3.2802805949209968, -0.0001116917021230428, 0)
Vector3D(3.277000314326076, -0.0001327916785196299, 0)
Vector3D(3.27372331401175, -0.00006987004825975429, 0)
Vector3D(3.270449590697738, -0.0001159169359442469, 0)
Vector3D(3.2671791411070403, -0.00011942362027232889, 0)
Vector3D(3.2639119619659334, -0.00015738574268908413, 0)
Vector3D(3.2606480500039674, -0.00012877876302182044, 0)
Vector3D(3.2573874019539635, -0.00010450325578365183, 0)
Vector3D(3.2541300145520093, -0.00008960528982356664, 0)
Vector3D(3.2508758845374572, -0.00009492714652436662, 0)
Vector3D(3.24762500865292, -0.00008410702125669545, 0)
Vector3D(3.244377383644267, -0.00008919168919785836, 0)
Vector3D(3.2411330062606227, -0.00008142861113664157, 0)
Vector3D(3.237891873254362, -0.00008141880499166954, 0)
Vector3D(3.2346539813811077, -0.00008140900865302924, 0)
Vector3D(3.2314193273997267, -0.00007446029897467321, 0)
Vector3D(3.228187908072327, -0.00007687939714064563, 0)
Vector3D(3.2249597201642546, -0.00006833235940950377, 0)

I tried to change friction, but it didn’t changed anything. What should i do to make ball moving more realistic?

package  
{
 import away3d
.cameras.Camera3D;
 
import away3d.containers.Scene3D;
 
import away3d.containers.View3D;
 
import away3d.lights.DirectionalLight;
 
import away3d.materials.ColorMaterial;
 
import away3d.materials.lightpickers.StaticLightPicker;
 
import away3d.materials.methods.FogMethod;
 
import flash.display.Sprite;
 
import flash.events.Event;
 
import flash.geom.Vector3D;
 
import jiglib.physics.RigidBody;
 
import jiglib.plugin.away3d4.Away3D4Mesh;
 
import jiglib.plugin.away3d4.Away3D4Physics;
 
/**
  * ...
  * @author Gugis
  */
 
public class Test extends Sprite
 {
  
var scene:Scene3D;
  var 
view:View3D;
  var 
camera:Camera3D;
  
  var 
physics:Away3D4Physics;
  private var 
sunLight:DirectionalLight;
  private var 
lightPicker:StaticLightPicker;
  private var 
fogMethod:FogMethod;
  
  var 
ground:RigidBody;
  var 
table:Away3D4Mesh;
  var 
cue:RigidBody;
  public function 
Test() 
  
{
   View
();
   
Physics();
   
Lights();
   
Table();
   
Ball();
   
Listeners();
  
}
  
  
private function Ball():void 
  {
   cue 
physics.createSphere(new ColorMaterial(0xFFFFFF), 5); 
   
cue.100;
   
cue.addWorldForce(new Vector3D(200), cue.currentState.position);
  
}
  
  
  
private function Table():void 
  {
   
var groundMaterial:ColorMaterial = new ColorMaterial(0x00ff00);
   
groundMaterial.lightPicker lightPicker;
   
groundMaterial.ambientColor 0x303040;
   
groundMaterial.ambient 1;
   
groundMaterial.specular .2;
   
groundMaterial.addMethod(fogMethod);
   
ground physics.createGround(groundMaterial45025011,true,0);
   
ground.friction 10;
   
ground.movable false;
   
ground.friction 20;
   
ground.restitution 0.1;
  
}
  
  
  
private function Listeners():void 
  {
   addEventListener
(Event.ENTER_FRAMEUpdate);
  
}
  
  
private function Update(e:Event):void 
  {
   trace
(cue.currentState.linVelocity);
   
physics.step();
   
view.render();
  
}
  
  
private function View():void 
  {
   camera 
= new Camera3D();
   
camera.0;
   
camera.250;
   
camera.= -400;
   
camera.rotationX 30;
   
   
view = new View3D(null,camera);
   
view.backgroundColor 0x0c00ff;
   
this.addChild(view);
  
}
  
  
private function Lights():void
  {
   sunLight 
= new DirectionalLight(-300, -300, -500);
   
sunLight.color 0xfffdc5;
   
sunLight.ambient 1;
   
view.scene.addChild(sunLight);
   
   
lightPicker = new StaticLightPicker([sunLight]);
   
fogMethod = new FogMethod(080000xcfd9de);
  
}
  
  
private function Physics():void 
  {
   physics 
= new Away3D4Physics(view8);
  
}
  
 }

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X