/// <summary> /// Create Arc from 3 given Points /// </summary> /// <param name="startPoint">Start-Point of the Arc</param> /// <param name="interPoint">A point anywhere the Arc</param> /// <param name="endPoint">End-Point of the Arc</param> /// <returns></returns> public static Arc FromDescriptorPoints(Vector2 startPoint, Vector2 interPoint, Vector2 endPoint) { const Direction calcdirection = Direction.RIGHT; // Calculate Rays from the 3 given Points var rays = RaysFromDescriptorPoints(startPoint, interPoint, endPoint, DirectionUtil.Switch(calcdirection)); // The two Rays intercept in the Arc's Middlepoint: var arcCenter = rays[0].Intersect(rays[1]); var arcRadius = new Vector2(startPoint, arcCenter).Length; // Take Vectors from these Points var middleToStart = new Vector2(arcCenter, startPoint); var middleToEnd = new Vector2(arcCenter, endPoint); // Calculate base vector var vbase = middleToStart.GetOrthogonalVector(Direction.RIGHT) * -1; var arcAngle = middleToEnd.AngleSignedTo(middleToStart, true); var newArc = new Arc( arcRadius, arcAngle, vbase) { Location = startPoint, Direction = DirectionUtil.Switch(calcdirection) }; return(newArc); }
public bool SearchForTarget(int mode) { // Motion-Sensing Mode if (mode == 0) { if (playerOldPos != playerCurrPos) { return(true); } else { return(false); } } // Seachlight Mode else { Vector3 vecToPlayer = playerCurrPos - bc.rb.position; float dp = Vector3.Dot(DirectionUtil.DirToVector(bc.facing), vecToPlayer.normalized); float angle = Mathf.Acos(dp); int walllayer = 9; // fill in with the layer # of anything that obstructs enemy vision if (angle <= bc.fieldOfView) { if (!Physics.Raycast(bc.rb.position, vecToPlayer, vecToPlayer.magnitude, (1 << walllayer))) { return(true); } } return(false); } }
public string HelpType(System.Type type) { string values = ""; List <string> typeList = GetEnumAsList(type); int i = 0; foreach (string typeValue in typeList) { if (i > 0) { values += "\n"; } values += typeValue.ToString(); i++; } if (type == typeof(Direction)) { values += "\n\nDefault: " + DirectionUtil.GetDefault(); } return(values); }
// TODO: fix movement, see card. // May need new to create new method, GetDirectionsToPlayer(shouldDiag) private void Move(Vector3 dir) { if (dir.x > 0) { currDir = Direction.right; } else if (dir.x < 0) { currDir = Direction.left; } else if (dir.y > 0) { currDir = Direction.up; } else { currDir = Direction.down; } if (CanMoveForEnemy(transform.position, currDir)) { MoveDir(dir); } else { Direction randomDir = (Direction)Random.Range(0, 4); if (CanMoveForEnemy(transform.position, randomDir)) { MoveDir(DirectionUtil.Convert(randomDir)); } } }
/// <summary> /// Returns the points in a triangular target (i.e. shotgun weapon) from origin to target. /// Only returns points within FOV. Moral: If you can see it, you can shoot it. /// fovAngle = spread of target /// </summary> /// <param name="location"></param> /// <param name="size"></param> /// <returns></returns> public List <Point> GetPointsForTriangularTargetInFOV(Point origin, Point target, Map mapLevel, int range, double fovAngle) { if (origin == target) { return(new List <Point>()); } List <Point> triangularPoints = new List <Point>(); double angle = DirectionUtil.AngleFromOriginToTarget(origin, target); for (int i = origin.x - range; i < origin.x + range; i++) { for (int j = origin.y - range; j < origin.y + range; j++) { if (new Point(i, j) == origin) { continue; } //Check for creature's FOV //If OK, check to see if it falls within a TriangularFOV (blast radius) if (i >= 0 && i < mapLevel.width && j >= 0 && j < mapLevel.height) { if (CheckTileFOV(i, j) && CreatureFOV.TriangularFOV(origin, angle, range, i, j, fovAngle)) { triangularPoints.Add(new Point(i, j)); } } } } return(triangularPoints); }
// make all cols OUTSIDE of a perimeter 'meet up' with all cols // INSIDE a perimeter described by @param area private void updateWithPerimeterSurrounding(Quad area) { foreach (Direction dir in DirectionUtil.TheDirectionsXZ()) { this.updateQuadBorderInDirection(area, dir); } }
//COPY PASTE OF ABOVE FUNC.! private List <PTwo> coordsXZOnInsideEdgeInDirection(Quad area, Direction dir) { PTwo nudge = DirectionUtil.NudgeCoordForDirectionPTwo(dir); Axis axis = DirectionUtil.AxisForDirection(dir); PTwo startPoint = area.origin; if (DirectionUtil.IsPosDirection(dir)) { if (axis == Axis.X) { startPoint.t += area.dimensions.t; } else { startPoint.s += area.dimensions.s; } } PTwo iterNudge = PTwo.Abs(nudge).flipSAndT(); int length = axis == Axis.X ? area.dimensions.t : area.dimensions.s; PTwo cursorPoint = startPoint; List <PTwo> result = new List <PTwo>(); for (int i = 0; i < length; ++i) { result.Add(cursorPoint + nudge); cursorPoint += iterNudge; } return(result); }
/// <summary> /// 设定起始点和真实朝向 /// </summary> public void SetData(RoadSectionData data, Vector3 position, Orientation toward) { this.data = data; transform.localPosition = position; this.orientation = toward; transform.eulerAngles = DirectionUtil.TowardToEuler(toward); }
private List <LightColumn> columnsThatColumnJustConnectedWith(LightColumn colAtY, int y) { List <LightColumn> result = new List <LightColumn>(); bool colExtentMinusOneEqualY = colAtY.extent() - 1 == y; bool colStartEqualY = colAtY.startP == y; foreach (PTwo co in DirectionUtil.SurroundingPTwoCoordsFromPTwo(colAtY.coord)) { DiscreteDomainRangeList <LightColumn> licols = m_lightColumnMap[co]; LightColumn justConnected = null; if (colExtentMinusOneEqualY) { justConnected = licols.rangeWithStartEqual(y); } else if (colStartEqualY) { justConnected = licols.rangeWithExtentMinusOneEqual(y); } else { justConnected = licols.rangeWithStartAndExtentMinusOneEqual(y); } if (justConnected != null) { result.Add(justConnected); } } return(result); }
public List <DiscreteDomainRangeList <LightColumn> > columnsOnBorderOfQuadInDirection(Quad areaXZ, Direction dir, bool wantWithin) { SimpleRange xRange = areaXZ.sSimpleRange(); SimpleRange zRange = areaXZ.tSimpleRange(); SimpleRange longRange; SimpleRange shortRange; int shortRangeStart; Axis axis = DirectionUtil.AxisForDirection(dir); if (axis == Axis.X) { longRange = zRange; shortRange = xRange; } else { longRange = xRange; shortRange = zRange; } if (DirectionUtil.IsPosDirection(dir)) { shortRangeStart = wantWithin ? shortRange.extentMinusOne() : shortRange.extent(); } else { shortRangeStart = wantWithin ? shortRange.start : shortRange.start - 1; } shortRange = new SimpleRange(shortRangeStart, 1); Quad area = (axis == Axis.X) ? new Quad(new PTwo(shortRange.start, longRange.start), new PTwo(shortRange.range, longRange.range)) : new Quad(new PTwo(longRange.start, shortRange.start), new PTwo(longRange.range, shortRange.range)); return(columnsWithin(area)); }
public List <LightColumn> lightColumnsAdjacentToAndFlushWithSimpleRangeAndPoint(SimpleRange colmRange, PTwo coord) { // PTwo coord = colm.coord; List <LightColumn> result = new List <LightColumn>(); foreach (PTwo surroundingCo in DirectionUtil.SurroundingPTwoCoordsFromPTwo(coord)) { DiscreteDomainRangeList <LightColumn> adjRangeList = this.lightColumnListAtOrNull(surroundingCo.s, surroundingCo.t); if (adjRangeList == null) { continue; } for (int i = 0; i < adjRangeList.Count; ++i) { LightColumn adjLightColumn = adjRangeList[i]; OverlapState overlap = colmRange.overlapStateWith(adjLightColumn.range); if (OverLapUtil.OverlapExists(overlap)) { result.Add(adjLightColumn); } } } return(result); }
private void CreateOutput(Molecule product, int direction) { var pos = new Vector2(0, 0).OffsetInDirection(direction, 1); new Product(this, pos, product.Rotation, product.ID); m_outputArms[product.ID] = new Arm(this, pos * 2, DirectionUtil.Rotate180(direction), MechanismType.Piston, extension: 2); }
private void Update() { smooth = Mathf.Max(follow.speed / 2.5f, 2); toward = follow.moveToward; Quaternion roatx = Quaternion.Euler(lookDownAngle, 0, 0); transform.localRotation = Quaternion.Lerp(transform.localRotation, DirectionUtil.TowardToQuaternion(toward) * roatx, Time.deltaTime * smooth); //transform.LookAt(follow.transform, camTargetPos); switch (toward) { case Orientation.North: camTargetPos = follow.transform.localPosition + Vector3.up * height + Vector3.back * faraway; break; case Orientation.East: camTargetPos = follow.transform.localPosition + Vector3.up * height + Vector3.left * faraway; break; case Orientation.South: camTargetPos = follow.transform.localPosition + Vector3.up * height + Vector3.forward * faraway; break; case Orientation.West: camTargetPos = follow.transform.localPosition + Vector3.up * height + Vector3.right * faraway; break; default: break; } transform.localPosition = Vector3.Lerp(transform.localPosition, camTargetPos, Time.deltaTime * smooth); }
void OnDrawGizmos() { Vector3 o = origin + Vector3.up; Vector3 e = origin + Vector3.up + DirectionUtil.TowardToVector3(moveToward) * 1000f; Debug.DrawLine(o, e); }
private void SetRandomHeading() { int randX = Game.Random.Next(-1, 2); int randY = Game.Random.Next(-1, 2); Heading = DirectionUtil.DirectionFromMove(randX, randY); }
public void PerformBehaviour(Entity target, Entity instigator) { if (!target.HasInventory()) { return; } var inventory = target.GetInventory(); foreach (var item in inventory.GetContent().Values) { if (item == null) { continue; } var position = target.GetPosition(); var distance = StaticRng.Random.NextDouble(0.2, 1); var rotation = StaticRng.Random.NextDouble(-Math.PI, Math.PI); var addition = DirectionUtil.CalculateVector((float)rotation) * (float)distance; var inventoryItem = _server.EntityFactory.Get((short)EntityTypeEnum.InventoryItem); inventoryItem.SetInventoryItem(item); inventoryItem.SetPosition(position + addition); _server.SpawnEntity(inventoryItem); } target.RemoveInventory(); }
public void PerformBehaviour(Entity target, Entity instigator) { var count = StaticRng.Random.Next(_minCount, _maxCount); if (count == 0) { return; } var distance = StaticRng.Random.NextDouble(0.2, 1); var rotation = StaticRng.Random.NextDouble(-Math.PI, Math.PI); var position = target.GetPosition(); var addition = DirectionUtil.CalculateVector((float)rotation) * (float)distance; var item = _server.ItemGeneratorDictionary[_itemType].Generate(); if (count > item.GetItemSpec().GetStackMax()) { count = item.GetItemSpec().GetStackMax(); Debug.Assert(true, "Unable to generate a stack as large as requested"); } item.SetCount((short)count); var inventoryItem = _server.EntityFactory.Get((short)EntityTypeEnum.InventoryItem); inventoryItem.SetInventoryItem(item); inventoryItem.SetPosition(position + addition); _server.Engine.SpawnEntity(inventoryItem); }
private bool IsConnectionBlocked(Vector3Int pos, Direction dir) { // check 3x3 outside // #.......# // ###-P-### // ??? // ??? // ??? pos += new Vector3Int(MID, MID, 0); Vector3Int posP = pos + DirectionUtil.Convert(DirectionUtil.PrevDir(dir)); Vector3Int posN = pos + DirectionUtil.Convert(DirectionUtil.NextDir(dir)); Vector3Int dirVec = DirectionUtil.Convert(dir); for (int i = 0; i < 3; i++) { pos += dirVec; posP += dirVec; posN += dirVec; if (grid[pos.x, pos.y] || grid[posP.x, posP.y] || grid[posN.x, posN.y]) { return(true); } } return(false); }
private string getRandomDirection(string strLastDir) { int lastDir = DirectionUtil.GetIntDirection(strLastDir); int randomDir = rnd.Next(0, 4); while (randomDir == lastDir) { randomDir = rnd.Next(0, 4); } switch (randomDir) { case 0: return("n"); case 1: return("e"); case 2: return("s"); case 3: return("w"); } return("n"); }
// public override PlayerState HandleInput() // { // if (pc.stateEnded && ((Input.GetButton("Attack1") && pc.canAttack1()) || (Input.GetButton("Attack2") && pc.canAttack2()))) // { // if (Input.GetButton("Attack1") && pc.canAttack1()) // { // return new Attack1(pc); // } // if (Input.GetButton("Attack2") && pc.canAttack2()) // { // return new Attack2(pc); // } // } // if (pc.stateEnded && (Input.GetButton("Vertical") || Input.GetButton("Horizontal"))) // { // if (Input.GetButton("Dash") && pc.canDash()) // { // Vector3 dir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); // return new Dash(pc, dir); // } // return new Running(pc); // } // return new PlayerMovement.Idle(pc); // } public override void Update() { this.moveX = Input.GetAxisRaw("Horizontal"); this.moveZ = Input.GetAxisRaw("Vertical"); if (pc.movementInput == Vector3.zero || (pc.canShield() && Input.GetAxisRaw("Shield") != 0) || (pc.canDash() && Input.GetAxisRaw("Dash") != 0) || (pc.canAttack1() && Input.GetAxisRaw("Attack1") != 0) || (pc.canAttack2() && Input.GetAxisRaw("Attack2") != 0)) { pc.stateEnded = true; // Debug.Log ("Shield " + Input.GetAxisRaw("Shield")); // Debug.Log ("Dash " + Input.GetAxisRaw("Dash")); // Debug.Log ("Attack1 " + Input.GetAxisRaw("Attack1")); // Debug.Log ("Attack2 " + Input.GetAxisRaw("Attack2")); pc.nextState = HandleInput(); // Debug.Log (pc.nextState); if (pc.nextState != null) { pc.stateEnded = false; } } else { Direction newDirection = DirectionUtil.FloatToDir(moveZ, moveX); pc.movingDirection = DirectionUtil.FloatToDir(moveZ, moveX); } }
private bool ComplexHallwayCheckSpot(Vector3Int pos, Direction dir) { // Check these positions // . . . // . v . // # # # pos += new Vector3Int(MID, MID, 0); Vector3Int posA = pos + DirectionUtil.Convert(dir); Vector3Int posB = posA + DirectionUtil.Convert(DirectionUtil.NextDir(dir)); Vector3Int posC = posA + DirectionUtil.Convert(DirectionUtil.PrevDir(dir)); // hacky code if (pos.x < 1 || MAX_SIZE - 2 < pos.x || pos.y < 1 || MAX_SIZE - 2 < pos.y) { return(false); } if (grid[posA.x, posA.y] || grid[posB.x, posB.y] || grid[posC.x, posC.y]) { return(false); } return(true); }
private void TryWalkerWalk(int x, int y, BaseEventData data) { if (this.gameFinished) { return; } // TODO: ignore collision between camera and walker if (this.mainWalker.IsWalking()) { return; } int destAddress = y * this.map.width + x; int[] currentFloorTerrain = this.map.terrains[this.CurrentFloor()]; List <int> route = Astar.Exec(this.mainWalker.data.address, destAddress, currentFloorTerrain, this.map.width); List <DirectionUtil.Direction> directions = DirectionUtil.AddressesToDirections(route, this.map.width, this.map.height); this.mainWalker.AppendWalkDirections(directions); switch (Rand.Next(10)) { case 0: this.mainWalker.PlaySe(Audio.GetSE(Audio.SE.Walk1)); break; case 1: this.mainWalker.PlaySe(Audio.GetSE(Audio.SE.Walk2)); break; default: break; } }
private IEnumerator Rotate() { if (!rotating) { rotating = true; float counter = 0f; float rate = 1f / rotationDuration; float startAngle = droneTransform.localEulerAngles.y; float toAngle = startAngle + DirectionUtil.ToAngle(direction); if (startAngle != toAngle) { while (counter < 1f) { counter += Time.deltaTime * rate; counter = Mathf.Clamp(counter, 0f, 1f); float yLerp = Mathf.LerpAngle(startAngle, toAngle, counter); Vector3 vLerp = new Vector3(0, yLerp, 0); droneTransform.localRotation = Quaternion.Euler(vLerp); yield return(null); } } rotating = false; } }
private void SpawnZombie(ITrigger trigger) { if (!CanSpawn) { return; } var entities = Engine.GetEntitiesInChunk(UniqueKey.ChunkLocation); var countInArea = entities.Count(item => item.GetIsZombie()); var countToSpawn = (int)Math.Floor((Engine.ChunkWorldSize * Engine.ChunkWorldSize * Density) - countInArea); if (countToSpawn <= 0) { return; } if (Engine.Entities.Count(x => x.GetIsZombie()) > 10) { return; } var zombies = Engine.SpawnEntityAtRandomObservedLocation((int)EntityTypeEnum.Zombie, UniqueKey.ChunkLocation, countToSpawn); foreach (var zombie in zombies) { var rotation = (float)(StaticRng.Random.NextDouble() * 2 * Math.PI); var speed = zombie.GetWalkSpeed(); var movementDir = DirectionUtil.CalculateVector(rotation); zombie.SetRotation(rotation); zombie.SetMovementVector(movementDir * speed); } }
public void SpawnPlayerDroppedItem(Item item, int quantity, MoleController playerController) { GamePosition spawnPosition = playerController.gamePos.add(DirectionUtil.getDirectionUnitVector(playerController.facing) * Player.DROP_DISTANCE); spawnPosition.descend(-0.5f); SpawnItem(item, quantity, spawnPosition); }
public static void SetTile(int x, int y, Tile tile, Vector2 v, bool overwrite = false) { Direction d = DirectionUtil.FromVector2(v); tile.tileattribs.rotation = d; SetTile(x, y, tile, overwrite); }
/// <summary> /// This function used to change ghosts direction /// Starts from getting and checking the two directions(perpendicular right and left) /// If one of the direction is valid, choose the direction randomly /// Both directions are not valid, change to the opposite dir of the current dir /// </summary> private void changeDir() { dirTime = Time.time + 1;//Ghost cannot change dir for a second Vector2 right = DirectionUtil.GetPerpenRightDir(direction); bool canTurnRight = checkDirValid(right); Vector2 left = DirectionUtil.GetPerpenLeftDir(direction); bool canTurnLeft = checkDirValid(left); if (canTurnRight || canTurnLeft) { int randomDir = Random.Range(0, 2); if (!canTurnLeft || (randomDir == 0 && canTurnRight)) { direction = right; } else { direction = left; } } else { direction = -direction; } }
private void SetDestination(Entity toProcess, Vector3 destination) { toProcess.LookAt(destination); var movementVector = toProcess.GetMovementVector(); var newMovementVector = DirectionUtil.CalculateVector(toProcess.GetRotation()) * movementVector.Length; toProcess.SetMovementVector(newMovementVector); }
private void SetDirection(Entity target, float newRotation) { var vector = target.GetMovementVector(); var newVector = DirectionUtil.CalculateVector(newRotation) * vector.Length; target.SetRotation(newRotation); target.SetMovementVector(newVector); }
private void UpdateBase() { string actionName = _currentIsWalking ? "Walk" : "Idle"; string directionName = DirectionUtil.GetActualName(_currentDirection); string animName = $"{actionName}/{directionName}"; spine.AnimationState.SetAnimation(0, animName, true); }