private void TickOnGround() { if (AKJetBody == null) { return; } if (AKJetBody.Sleeping) { return; } float rayLength = .7f; leftWheel.onGround = false; rightWheel.onGround = false; MapObjectAttachedHelper Leftwheel = GetFirstAttachedObjectByAlias("leftwheel") as MapObjectAttachedHelper; MapObjectAttachedHelper Rightwheel = GetFirstAttachedObjectByAlias("rightwheel") as MapObjectAttachedHelper; if (Leftwheel == null || Rightwheel == null) { return; } Vec3 pos; Quat rot; Vec3 scl; Vec3 downDirection = AKJetBody.Rotation * new Vec3(0, 0, -rayLength); //leftwheel { Leftwheel.GetGlobalTransform(out pos, out rot, out scl); Vec3 start = pos - downDirection; Ray ray = new Ray(start, downDirection); RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); bool collision = false; Vec3 collisionPos = Vec3.Zero; foreach (RayCastResult result in piercingResult) { if (Array.IndexOf(PhysicsModel.Bodies, result.Shape.Body) != -1) { continue; } collision = true; collisionPos = result.Position; break; } if (collision) { leftWheel.onGround = true; } } //right wheel { Rightwheel.GetGlobalTransform(out pos, out rot, out scl); Vec3 start = pos - downDirection; Ray ray = new Ray(start, downDirection); RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); bool collision = false; Vec3 collisionPos = Vec3.Zero; foreach (RayCastResult result in piercingResult) { if (Array.IndexOf(PhysicsModel.Bodies, result.Shape.Body) != -1) { continue; } collision = true; collisionPos = result.Position; break; } if (collision) { rightWheel.onGround = true; } } if (rightWheel.onGround == false) { playedright = 0; } if (rightWheel.onGround == true && playedright == 0) { SoundPlay3D(Type.SoundWheel, .7f, true); playedright = 1; } if (leftWheel.onGround == false) { playedleft = 0; } if (leftWheel.onGround == true && playedleft == 0) { SoundPlay3D(Type.SoundWheel, .7f, true); playedleft = 1; } }
private void Footsteps() { if (string.IsNullOrEmpty(Type.SoundFoot1)) { return; } if (mainBody == null) { return; } if (mainBody.Sleeping) { return; } float rayLength = .7f; leftFoot.onGround = false; rightFoot.onGround = false; MapObjectAttachedHelper Leftfoot = GetFirstAttachedObjectByAlias("leftfoot") as MapObjectAttachedHelper; MapObjectAttachedHelper Rightfoot = GetFirstAttachedObjectByAlias("rightfoot") as MapObjectAttachedHelper; if (Leftfoot == null || Rightfoot == null) { return; } Vec3 pos; Quat rot; Vec3 scl; Vec3 downDirection = mainBody.Rotation * new Vec3(0, 0, -rayLength); //leftfoot { Leftfoot.GetGlobalTransform(out pos, out rot, out scl); Vec3 start = pos - downDirection; Ray ray = new Ray(start, downDirection); RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); bool collision = false; Vec3 collisionPos = Vec3.Zero; foreach (RayCastResult result in piercingResult) { if (Array.IndexOf(PhysicsModel.Bodies, result.Shape.Body) != -1) { continue; } collision = true; collisionPos = result.Position; break; } if (collision) { leftFoot.onGround = true; } } //right foot { Rightfoot.GetGlobalTransform(out pos, out rot, out scl); Vec3 start = pos - downDirection; Ray ray = new Ray(start, downDirection); RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); bool collision = false; Vec3 collisionPos = Vec3.Zero; foreach (RayCastResult result in piercingResult) { if (Array.IndexOf(PhysicsModel.Bodies, result.Shape.Body) != -1) { continue; } collision = true; collisionPos = result.Position; break; } if (collision) { rightFoot.onGround = true; } } if (rightFoot.onGround == false) { playedright = 0; } if (rightFoot.onGround == true && playedright == 0) { playedright = 1; if (PlayFootSound()) { bduplicatestoperbool = true; } } if (leftFoot.onGround == false) { playedleft = 0; } if (leftFoot.onGround == true && playedleft == 0) { playedleft = 1; if (PlayFootSound()) { bduplicatestoperbool = true; } } if (bduplicatestoperbool) { duplicatestoper += TickDelta; if (duplicatestoper > 0.3f) { bduplicatestoperbool = false; duplicatestoper = 0; } } }