Physics piston type movement?

Software: Away3D 4.x

Alex Bogartz, Sr. Member
Posted: 17 September 2011 12:51 AM   Total Posts: 216

Is it possible to make a rigid body (or something similar) move like a piston along a given axis?  I’m trying to make a ledge move back and forth along the x-axis.  The ledge has a mass of zero so it doesn’t fall and is supposed to be “floating”.  Any ideas?

   

Alex Bogartz, Sr. Member
Posted: 17 September 2011 03:09 PM   Total Posts: 216   [ # 1 ]

The answer lies somewhere in here, perhaps?  I haven’t had enough time to play with it.

https://github.com/away3d/awayphysics-examples-fp11/blob/e7cd5ba317ec0cc4d390ee1c45572b5ddd1c4166/src/ConstraintTest.as

If anyone has a quick explanation I’d be very grateful.

   

John Brookes, Moderator
Posted: 17 September 2011 04:19 PM   Total Posts: 732   [ # 2 ]

In that example theres one called slider. It uses AWPGeneric6DofConstraint
Instead of passing two meshes, just pass one.
It should then be a constraint between the ledge and the world.

ps there is a physics section on the forum :p

   

Alex Bogartz, Sr. Member
Posted: 17 September 2011 10:32 PM   Total Posts: 216   [ # 3 ]

New physics forum?  YES!

Thanks, I’ll take a look!

   

Alex Bogartz, Sr. Member
Posted: 19 September 2011 07:28 PM   Total Posts: 216   [ # 4 ]

Hi, so there’s one thing about those physics examples that doesn’t seem ideal, and that is that you’re using a timer to decide when to change directions.  Part of the problem is that there’s no event fired when a constraint object reaches it’s end point, is there?  So I made a new function in AWPGeneric6DofConstraint.  It uses AS3 Signals (I know you guys are using that but maybe this idea would be helpful using Events?):

public function testForLimit():void
  {
   
if (getTranslationalLimitMotor().targetVelocity.0)
   
{
    
if (getTranslationalLimitMotor().lowerLimit.getTranslationalLimitMotor().currentLinearDiff.100 > -1)
    
{
     xLimitReached
.dispatch(this);
    
}
   } 
else
   
{
    
if (getTranslationalLimitMotor().upperLimit.- (getTranslationalLimitMotor().currentLinearDiff.100) < 1)
    
{
     xLimitReached
.dispatch(this);
    
}
   }
   
if (getTranslationalLimitMotor().targetVelocity.0)
   
{
    
if (getTranslationalLimitMotor().lowerLimit.getTranslationalLimitMotor().currentLinearDiff.100 > -1)
    
{
     yLimitReached
.dispatch(this);
    
}
   } 
else
   
{
    
if (getTranslationalLimitMotor().upperLimit.- (getTranslationalLimitMotor().currentLinearDiff.100) < 1)
    
{
     yLimitReached
.dispatch(this);
    
}
   }
   
if (getTranslationalLimitMotor().targetVelocity.0)
   
{
    
if (getTranslationalLimitMotor().lowerLimit.getTranslationalLimitMotor().currentLinearDiff.100 > -1)
    
{
     zLimitReached
.dispatch(this);
    
}
   } 
else
   
{
    
if (getTranslationalLimitMotor().upperLimit.- (getTranslationalLimitMotor().currentLinearDiff.100) < 1)
    
{
     zLimitReached
.dispatch(this);
    
}
   } 

So in my game loop, I do something like this:

if (generic6Dof)
    
{
     generic6Dof
.testForLimit();     
    

When I create the constraint, I add this:

generic6Dof.xLimitReached.add(reverseLedge

Which simply triggers this:

private function reverseLedge(constraint:AWPGeneric6DofConstraint):void
  {
   constraint
.getTranslationalLimitMotor().targetVelocity = new Vector3D(-constraint.getTranslationalLimitMotor().targetVelocity.x00);
  

Any thoughts on this approach?  Am I missing something built in?

Thanks!

 

   

Yang Li, Administrator
Posted: 20 September 2011 03:34 AM   Total Posts: 80   [ # 5 ]

looks good, will test. any idea about angular motor?

   

Alex Bogartz, Sr. Member
Posted: 20 September 2011 03:04 PM   Total Posts: 216   [ # 6 ]
Yang Li - 20 September 2011 03:34 AM

looks good, will test. any idea about angular motor?

You mean triggering an event when the target rotation is met?  I’m not sure yet.  I was just approaching this like you might in a tweening engine where you can set an onComplete function to fire.  I think that would be a really useful addition to the constraints.

   

John Brookes, Moderator
Posted: 20 September 2011 04:58 PM   Total Posts: 732   [ # 7 ]

Maybe just check the linear/angular velocity

   

Alex Bogartz, Sr. Member
Posted: 20 September 2011 05:02 PM   Total Posts: 216   [ # 8 ]

I just personally prefer the event or signal driven method.  Rather than have a list of items to test for, I’d like to just add a listener and wait for each event to trigger. 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X