public void Teleport(Vector3 position) { _targetPosition = CorrectPosition(position, false); transform.position = _targetPosition; ResetVelocity(); _lastValidNode = FindNode(transform.position); }
private void UpdateTargetPosition(Vector3 newPosition) { var newNode = FindNode(newPosition); if (newNode != null) { _lastValidNode = newNode; newPosition = CorrectPosition(newNode.Hit, false); _targetPosition = newPosition; } }
public void AddCollision(NodeCollisionManager manager, NodeManager nodeManager) { NodeHit hit = CalculateHit(nodeManager); if (fadingHits.ContainsKey(nodeManager) == true) { fadingHits.Remove(nodeManager); } hits.Add(nodeManager, hit); OnHit?.Invoke(nodeManager, hit); }
private NodeHit CalculateHit(NodeManager nodeManager) { Vector2 point = transform.position; NodeHit hit = new NodeHit(); hit.nodeManager = nodeManager; hit.node = nodeManager.GetClosestNode(point); hit.normal = hit.node.side == NodeSide.Left ? new Vector2(hit.node.velocity.y, -hit.node.velocity.x).normalized : new Vector2(-hit.node.velocity.y, hit.node.velocity.x).normalized; return(hit); }
public NodeLocation getMouseOverLocation(int x, int y) { Ray r = myEditor.camera.getPickRay(x, (int)ImGui.displaySize.Y - y); myCurrentHit = myEditor.world.getNodeIntersection(r, myEditor.camera.near, myEditor.camera.far); myClampedLocation = null; if (myCurrentHit != null) { if (myEditor.cursorDepth <= myCurrentHit.node.depth) { Node n = myCurrentHit.node; myClampedLocation = myCurrentHit.node.location; while (n.depth != myEditor.cursorDepth) { n = n.myParent; myClampedLocation = n.location; } } else { myClampedLocation = new NodeLocation(myCurrentHit.location, myEditor.cursorDepth); //may need to adjust the clamped location to be within the node that is hit //since sometimes the conversion to a clamped node location causes it to be the next node since //nodes boundaries are [min..max) inclusion if (myCurrentHit.node.contains(myClampedLocation) == false) { foreach (Face f in Enum.GetValues(typeof(Face))) { NodeLocation nl = myClampedLocation.getNeighborLocation(f); if (myCurrentHit.node.contains(nl) == true) { myClampedLocation = nl; break; } } } } } return(myClampedLocation); }
private void FixedUpdate() { List <NodeManager> keys = hits.Keys.ToList(); foreach (NodeManager manager in keys) { NodeHit hit = CalculateHit(manager); hits[manager] = hit; } List <NodeManager> fadingKeys = fadingHits.Keys.ToList(); foreach (NodeManager manager in fadingKeys) { NodeHit hit = fadingHits[manager]; hit.node.velocity *= hitFade; hit.normal *= hitFade; if (hit.node.velocity.magnitude <= hitFadeThreshold && hit.normal.magnitude <= hitFadeThreshold) { fadingHits.Remove(manager); } } }
private void Awake() { _lastValidNode = FindNode(transform.position); }