public virtual void AdjustCollision(PhysObj obj) { if (playerTangible != PlayerObjectMode.None && obj.playerTangible != PlayerObjectMode.None) { if (playerTangible != obj.playerTangible) return; } if (!obj.isSolidObject || !hitBox.CheckCollision(obj.hitBox)) { return; } AABB aabb = obj.hitBox.GetAABB(); Vector2 solution = aabb.SolveCollision(hitBox.GetAABB()); hitBox.SetPosition(hitBox.GetPosition() + solution); Vector2 newpos = hitBox.GetPosition(); if (newpos.Y != position.Y) speed.Y = Level.SolveBounce(this, true); if (newpos.X != position.X) speed.X = Level.SolveBounce(this, false); if (newpos.Y < position.Y) { state = PhysState.Grounded; frictionMultiplier = EnvironmentData.NORMAL; obj.currentMass += currentMass; if (obj.affectsResident && !obj.residentList.Contains(this)) obj.residentList.Add(this); } if (newpos.Y > position.Y) { speed.Y = obj.speed.Y; if (speed.Y < 0) speed.Y = 0; } Vector2 prevPosition = position; position = newpos; Vector2 dPos = position - prevPosition; foreach (PhysObj resident in residentList) { resident.position += dPos; resident.hitBox.SetPosition(resident.position); } }
public virtual void CollisionEnvironmentResponse() { if (!isSolidEnvironment) return; state = PhysState.Air; hitBox.SetPosition(tempPosition); Level.CheckEnvironment(this); }