public PlayerSpriteState(GameEventListenerId listenerId, string spriteName, double firstSequenceLength, Vector2[] colliderPoints, int direction) : base(listenerId, spriteName, firstSequenceLength, colliderPoints) { this.fixer = this.gameObject.GetComponent <CollisionDistanceFixer>(); this.edge = 0; foreach (Vector2 point in colliderPoints) { if (Math.Sign(point.x) == Math.Sign(direction) && Math.Abs(point.x) > this.edge) { this.edge = Math.Abs(point.x); } } }
public override void HandleGameEvent(GameEvent gameEvent) { base.Tick(); if (gameEvent.GetName().Equals("collision")) { GameObject go = gameEvent.GetGameData <GameObject>(); CollisionDistanceFixer fixer = go.GetComponent <CollisionDistanceFixer>(); if (fixer != null) { double total = Math.Abs(fixer.GetVelocity()) + Math.Abs(this.GetVelocity()); float distance = (float)(this.GetEdge() + fixer.GetEdge()) - Vector3.Distance(this.transform.position, go.transform.position); if (total != 0) { new TypedGameEvent <double>(this.GetListenerId(), "fixCollision", -1 * distance * ((this.GetVelocity() / total)), true); } } } else if (gameEvent.GetName().Equals("fixCollision")) { this.transform.Translate(new Vector3((float)gameEvent.GetGameData <double>(), 0, 0)); } }
public PlayerSpriteState(GameEventListenerId listenerId, string spriteName, double firstSequenceLength) : base(listenerId, spriteName, firstSequenceLength) { this.edge = 0.5; this.fixer = this.gameObject.GetComponent <CollisionDistanceFixer>(); }