Sigma
|
|
« Reply #23 on: November 24, 2009, 09:32:26 PM » |
|
when my character stands at the very tip of a platform it is not jumping?
Code Below:
_body.m_userData.width = 20; _body.m_userData.height = 50; private function jump():void { if (_body.GetLinearVelocity().y > -1) { var Hit = GetBodyAtPoint(_body.m_userData.x, _body.m_userData.y+ (_body.m_userData.height/2+2), true);//Under
var Hit1 = GetBodyAtPoint(_body.m_userData.x-(_body.m_userData.width/2)+2, _body.m_userData.y+(_body.m_userData.height/2+2), true);//Down-Left
var Hit2 = GetBodyAtPoint(_body.m_userData.x+(_body.m_userData.width/2)-2, _body.m_userData.y+(_body.m_userData.height/2+2), true);//Down-Right if (Hit != null && Hit.m_userData != _body.m_userData ) { _body.ApplyImpulse(new b2Vec2(0.0, -GameConstants.jumpVelocity), _body.GetWorldCenter());//Applys and impuls to the player. (Makes it jump) } else if (Hit1 != null && Hit1.m_userData != _body.m_userData && Hit2 != null && Hit2.m_userData != _body.m_userData) { _body.ApplyImpulse(new b2Vec2(0.0, -GameConstants.jumpVelocity), _body.GetWorldCenter());//Applys and impuls to the player. (Makes it jump) } } _body.m_sweep.a = 0; }
public function GetBodyAtPoint(px:Number, py:Number, includeStatic:Boolean = false) : b2Body { // Make a small box. var px2 = px/Environment.RATIO; var py2 = py/Environment.RATIO; var PointVec:b2Vec2 = new b2Vec2(); PointVec.Set(px2, py2); var aabb:b2AABB = new b2AABB(); aabb.lowerBound.Set(px2 - 0.001, py2 - 0.001); aabb.upperBound.Set(px2 + 0.001, py2 + 0.001); // Query the world for overlapping shapes. var k_maxCount:int = 10; var shapes:Array = new Array(); var count:int = Environment._world.Query(aabb, shapes, k_maxCount); var body:b2Body = null; // The loop that seeks for the body: for (var i:int = 0; i <count; ++i) { if (shapes.m_body.IsStatic() == false || includeStatic) { var tShape:b2Shape = shapes as b2Shape; var inside:Boolean = tShape.TestPoint(tShape.m_body.GetXForm(), PointVec); if (inside) { body = tShape.m_body; break; } } } return body; }
|