Hey all,
I have a feeling I'm going about this all wrong. I'm trying to add moving platforms and elevators into my game. I'm currently using TweenMax to tween the position of a static body. It seems to work pretty well when the body moves down, but when it moves upward the objects riding on the body overlap each other. I've tried prismatic joints and kinematic bodies too and I just can't get a good solution.
Here's the test I've been using:
Any help would be greatly appreciated.
Thanks,
Bryan
I have a feeling I'm going about this all wrong. I'm trying to add moving platforms and elevators into my game. I'm currently using TweenMax to tween the position of a static body. It seems to work pretty well when the body moves down, but when it moves upward the objects riding on the body overlap each other. I've tried prismatic joints and kinematic bodies too and I just can't get a good solution.
Here's the test I've been using:
Code:
package TestBed{
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Common.*;
import Box2D.Common.Math.*;
import com.greensock.*;
import com.greensock.easing.*;
public class TestElevator extends Test{
public function TestElevator(){
// Set Text field
Main.m_aboutText.text = "Elevator";
var ground:b2Body = m_world.GetGroundBody();
var body:b2Body;
var sd:b2PolygonShape;
var bd:b2BodyDef;
var fixtureDef:b2FixtureDef = new b2FixtureDef();
bd = new b2BodyDef();
bd.type = b2Body.b2_staticBody;
bd.position.Set(0,0);
sd = new b2PolygonShape();
sd.SetAsBox(40 / m_physScale,5 / m_physScale);
fixtureDef.shape = sd;
bd.position.Set(100.0/m_physScale, 180/m_physScale);
body = m_world.CreateBody(bd);
body.CreateFixture(fixtureDef);
var position:b2Vec2=body.GetPosition().Copy();
TweenMax.to(position,2,{
y:300/m_physScale,
yoyo:true,
repeat:-1,
ease:Linear.easeNone,
onUpdate:body.SetPositionAndAngle,
onUpdateParams:[position,body.GetAngle()]
});
bd.type = b2Body.b2_dynamicBody;
// Create a payload
for(var i:int=0;i<5;i++){
sd = new b2PolygonShape()
sd.SetAsBox(15 / m_physScale, 4 / m_physScale);
fixtureDef.shape = sd;
fixtureDef.density = 2.0;
bd.position.Set(100.0/m_physScale, (50)/m_physScale);
body = m_world.CreateBody(bd);
body.CreateFixture(fixtureDef);
}
}
}
}
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Common.*;
import Box2D.Common.Math.*;
import com.greensock.*;
import com.greensock.easing.*;
public class TestElevator extends Test{
public function TestElevator(){
// Set Text field
Main.m_aboutText.text = "Elevator";
var ground:b2Body = m_world.GetGroundBody();
var body:b2Body;
var sd:b2PolygonShape;
var bd:b2BodyDef;
var fixtureDef:b2FixtureDef = new b2FixtureDef();
bd = new b2BodyDef();
bd.type = b2Body.b2_staticBody;
bd.position.Set(0,0);
sd = new b2PolygonShape();
sd.SetAsBox(40 / m_physScale,5 / m_physScale);
fixtureDef.shape = sd;
bd.position.Set(100.0/m_physScale, 180/m_physScale);
body = m_world.CreateBody(bd);
body.CreateFixture(fixtureDef);
var position:b2Vec2=body.GetPosition().Copy();
TweenMax.to(position,2,{
y:300/m_physScale,
yoyo:true,
repeat:-1,
ease:Linear.easeNone,
onUpdate:body.SetPositionAndAngle,
onUpdateParams:[position,body.GetAngle()]
});
bd.type = b2Body.b2_dynamicBody;
// Create a payload
for(var i:int=0;i<5;i++){
sd = new b2PolygonShape()
sd.SetAsBox(15 / m_physScale, 4 / m_physScale);
fixtureDef.shape = sd;
fixtureDef.density = 2.0;
bd.position.Set(100.0/m_physScale, (50)/m_physScale);
body = m_world.CreateBody(bd);
body.CreateFixture(fixtureDef);
}
}
}
}
Any help would be greatly appreciated.
Thanks,
Bryan