public bool Contains(Vector2 point) { var b1 = point.Sign(Point1, Point2) < 0.0f; var b2 = point.Sign(Point2, Point3) < 0.0f; var b3 = point.Sign(Point3, Point1) < 0.0f; return ((b1 == b2) && (b2 == b3)); }
public bool RotateHeadingToFacePosition(Vector2 target) { Vector2 toTarget = (target - Position).normalized; //first determine the angle between the heading vector and the target float angle = Mathf.Acos(Vector2.Dot(_heading, toTarget)); //return true if the player is facing the target if (angle < float.Epsilon) { return(true); } //clamp the amount to turn to the max turn rate if (angle > _maxTurnRate) { angle = _maxTurnRate; } //notice how the direction of rotation has to be determined when creating //the rotation matrix Quaternion rotate = Quaternion.AngleAxis(angle * _heading.Sign(toTarget), Vector3.forward); _heading = rotate * _heading; _velocity = rotate * _velocity; //finally recreate m_vSide _side = _heading.Perpendicular(); return(false); }
private static void Player_DashBegin(On.Celeste.Player.orig_DashBegin orig, Player self) { orig(self); if (HasDreamTunnelDash) { dreamTunnelDashAttacking = true; dreamTunnelDashTimer = self.GetData().Get <float>("dashAttackTimer"); // Ensures the player enters the dream tunnel dash state if dashing into a fast moving block // Because of how it works, it removes dashdir leniency :( DynData <Player> playerData = self.GetData(); Vector2 lastAim = Input.GetAimVector(self.Facing); Vector2 dir = lastAim.Sign(); if (!self.CollideCheck <Solid, DreamBlock>() && self.CollideCheck <Solid, DreamBlock>(self.Position + dir)) { self.Speed = self.DashDir = lastAim; self.MoveHExact((int)dir.X, playerData.Get <Collision>("onCollideH")); self.MoveVExact((int)dir.Y, playerData.Get <Collision>("onCollideV")); } if (NextDashFeather) { FeatherMode = true; NextDashFeather = false; } } HasDreamTunnelDash = false; }
/* * Given a previous input and a current input, determine if there should be a change in * direction. When a user is pressing more than one directional input, we have to resolve to a single direction. * This isn't as trivial as it seems, and really comes down to preference, but this method weights * the recent direction more (e.g. if already heading right and up is introduced, go up) */ public static Cardinal?GetDirectionChange(Vector2 input, Vector2 prevInput) { // Get the sign vectors, which just tell us if *any* amount of x or y are present and in what direction var inputSignVec = input.Sign(); var prevInputSignVec = prevInput.Sign(); // If the user has stopped pressing inputs or is pressing contradictory inputs if (inputSignVec == Vector2.zero) { return(null); } if (inputSignVec == prevInputSignVec) { return(null); } // If the new input only has one dimension, there's no conflict to resolve if (inputSignVec.IsCardinal()) { return(inputSignVec.ToCardinal()); } /* * Otherwise the input has two dimensions. Go in the newly introduced direction*/ return((inputSignVec - prevInputSignVec).ToCardinal()); }
/// <summary> /// Untested and likely broken ray-grid traversal for testing if two points can be walked between /// Planned to be used to smoothen the results from A* even further, and to replace the linecast being done by followers /// </summary> /// <param name="start3"></param> /// <param name="end3"></param> /// <returns></returns> public bool CanWalkBetween(Vector3 start3, Vector3 end3) { Node node = NodeFromWorldPoint(start3); Node endNode = NodeFromWorldPoint(end3); var start = new Vector2(start3.x, start3.z); var end = new Vector2(end3.x, end3.z); Vector2 diff = end - start; Vector2Int sign = diff.Sign(); var tMax = new Vector2(); var tDelta = new Vector2(); if (sign.x != 0) { tDelta.x = sign.x * nodeLength / diff.x; } else { tDelta.x = float.PositiveInfinity; } if (sign.x > 0) { tMax.x = tDelta.x * (1 - start.x + Mathf.Floor(start.x)); } else { tMax.x = tDelta.x * (start.x + Mathf.Floor(start.x)); } if (sign.y != 0) { tDelta.y = sign.y * nodeLength / diff.y; } else { tDelta.y = float.PositiveInfinity; } if (sign.y > 0) { tMax.y = tDelta.y * (1 - start.y + Mathf.Floor(start.y)); } else { tMax.y = tDelta.y * (start.y + Mathf.Floor(start.y)); } do { if (!node.getWalkable()) { return(false); } if (tMax.x < tMax.y) { tMax.x += tDelta.x; node = grid[node.indexX + sign.x, node.indexY]; } else { tMax.y += tDelta.y; node = grid[node.indexX, node.indexY + sign.y]; } } while (!node.Equals(endNode)); return(true); }
public bool Contains(Vector2 point) { var p1 = TopLeft; var p2 = TopRight; var p3 = BottomRight; var p4 = BottomLeft; var b1 = point.Sign(p1, p2) < 0.0f; var b2 = point.Sign(p2, p3) < 0.0f; var b3 = point.Sign(p3, p4) < 0.0f; var b4 = point.Sign(p4, p1) < 0.0f; return ((b1 == b2) && (b2 == b3) && (b3 == b4)); }