public PlayerState ResolveCollisionState(PlayerState state, FGRectCollider[] colliders, float dt) { for (int i = 0; i < 2; i++) { Vector2 vel = new Vector2(0, 0); if (i == 0) { vel = new Vector2(state.stateData.velocity.x, 0); } else { vel = new Vector2(0, state.stateData.velocity.y); } Vector2 dp = vel * dt; //check collisions after dv would be applied FGRectCollider nextRect = GetNextRect(dp); foreach (FGRectCollider other in colliders) { if (Collides(nextRect, other)) { if (other.type == CollidableType.STATIC) { state += ResolveStaticCollision(nextRect, other, vel); } } } } return(state); }
PlayerStateData ResolveStaticCollision(FGRectCollider nextFrame, FGRectCollider other, Vector2 velocity) { PlayerStateData resolutionState = new PlayerStateData(); if (Collides(nextFrame, other)) { Vector2 overlap = CheckRectCollision(nextFrame.GetRect(), velocity, other.GetRect()); ResolveCollision(ref resolutionState, overlap); } return(resolutionState); }
private void Awake() { _colliders = new List <FGRectCollider>(); _position = new Vector2(0, 0); _velocity = new Vector2(0, 0); _rt = this.GetComponent <RectTransform>(); for (int i = 0; i < type.Length; i++) { FGRectCollider collider = new FGRectCollider(_rt); collider.type = type[i]; _colliders.Add(collider); } }
PlayerState ResolveHitBoxes(Player player, PlayerState potentialState) { PlayerState state = potentialState; foreach (Hitbox hitbox in _hitBoxBounds) { if (!hitbox.IsOwner(ref player) && FGRectCollider.Collides(hitbox, player.hurtbox)) { state = Hurtbox.ReceiveHit(state, hitbox); } } return(state); }
public void AddDebugCollider(FGRectCollider collider) { Rect r = collider.GetRect(); Vector3 topLeft = new Vector2(r.position.x, r.position.y + r.size.y); Vector3 bottomLeft = new Vector2(r.position.x, r.position.y); Vector3 topRight = new Vector2(r.position.x + r.size.x, r.position.y + r.size.y); Vector3 bottomRight = new Vector2(r.position.x + r.size.x, r.position.y); DrawRectRequest rect = new DrawRectRequest(); rect.topLeft = topLeft; rect.topRight = topRight; rect.bottomLeft = bottomLeft; rect.bottomRight = bottomRight; rect.color = _colors[collider.type]; _rectStack.Add(rect); }
public void AddCollider(FGRectCollider collider) { _colliders.Add(collider); }
public static bool Collides(FGRectCollider first, FGRectCollider other) { return(first.GetRect().Overlaps(other.GetRect(), true)); }