/** * Check if Character is grounded by spherecasting the ground. */ private bool CheckGrounding(out RaycastHit hitInfo) { float gravSpeed = raycastOffset + (gravitySpeed + fallSpeedIncrementer) * Time.deltaTime; Vector3 position = rb.position + new Vector3(0, raycastOffset, 0); DebugExtension.DebugArrow(position, -transform.up * gravSpeed); Boolean hitGround = Physics.Raycast(position, -transform.up, out hitInfo, gravSpeed, 1 | (1 << 10)); if (hitGround) { if (hitInfo.collider.isTrigger) { return(false); } if (Vector3.Dot(hitInfo.normal, Vector3.up) > groundingAngle) { gravitySpeed = GRAVITY * fallSpeed; currentJumpNumber = 0; IsJumping = false; return(true); } } return(false); }
/// <summary> /// Check joints between two bricks. /// </summary> /// <returns><c>true</c>, if bricks can be joined in this position, <c>false</c> otherwise.</returns> /// <param name="brickJoints">Brick1 joints.</param> /// <param name="otherJoints">Brick2 joints.</param> bool CheckJoints(AgaQ.Bricks.Joints.Joint[] brickJoints, AgaQ.Bricks.Joints.Joint[] otherJoints) { foreach (var otherJoint in otherJoints) { //iterate over dragg brick joints foreach (var dragJoint in brickJoints) { //compare joints var distance = (dragJoint.transform.position - otherJoint.transform.position).magnitude; //compare distance float distanceScale = Mathf.Max(otherJoint.transform.lossyScale.x, dragJoint.transform.lossyScale.x); if (distance > positionAccuracy && distance <= jointColisionDistance * distanceScale && !(dragJoint is FemaleBorderJoint) && !(otherJoint is FemaleBorderJoint)) { DebugExtension.DebugArrow(otherJoint.transform.position, dragJoint.transform.position, Color.yellow, 1); return(false); } //compare distance, typ of joints and rotations if (distance <= positionAccuracy && (!AgaQ.Bricks.Joints.Joint.AreJoinable(dragJoint, otherJoint) || Quaternion.Angle(dragJoint.transform.rotation, otherJoint.transform.rotation) > rotationAccuracy)) { return(false); } } } return(true); }
public raycastObj Raycast(float _distance) { Vector3 positionRight = new Vector3(transform.position.x + transform.localScale.x / 2, transform.position.y - 0.4f, transform.position.z); Vector3 positionleft = new Vector3(transform.position.x - transform.localScale.x / 2, transform.position.y - 0.4f, transform.position.z); raycastObj objHit; RaycastHit Hit_1, Hit_2; objHit.HitObj = gameObject; objHit.HitMoveBoids = gameObject.GetComponent <MoveBoids>(); objHit.HitRb = gameObject.GetComponent <Rigidbody>(); objHit.right = Physics.Raycast(positionRight, transform.TransformDirection(Vector3.right), out Hit_1, _distance); objHit.left = Physics.Raycast(positionleft, transform.TransformDirection(Vector3.left), out Hit_2, _distance); objHit.ptLeft = positionleft + Vector3.left * _distance / 2; objHit.ptRight = positionRight + Vector3.right * _distance / 2; if (debugDraw) { DebugExtension.DebugArrow(positionRight, transform.TransformDirection(Vector3.right) * _distance, Color.magenta); DebugExtension.DebugArrow(positionleft, transform.TransformDirection(Vector3.left) * _distance, Color.magenta); DebugExtension.DebugPoint(objHit.ptLeft, Color.magenta, 0.20f); DebugExtension.DebugPoint(objHit.ptRight, Color.magenta, 0.20f); } if (objHit.left || objHit.right) { //Debug.LogWarning(" Je touche un bord "); } return(objHit); }
void OnDrawGizmosSelected() { if (Application.isPlaying) { DrawDebugJoint(); } //Gizmos.DrawWireSphere(this.transform.position, sensorParameters.ViewDistance); DebugExtension.DebugCone(this.transform.position, this.transform.forward.normalized * sensorParameters.ViewDistance, Color.white, sensorParameters.ViewAngle / 2); foreach (Creature target in observedCreatures) { if (target == null) { return; } Vector3 dirToTarget = (target.transform.position - transform.position).normalized; float dstToTarget = Vector3.Distance(transform.position, target.transform.position); DebugExtension.DebugArrow(this.transform.position, dirToTarget * dstToTarget, Color.red); } foreach (Edible target in observedEdibles) { if (target == null) { return; } Vector3 dirToTarget = (target.transform.position - transform.position).normalized; float dstToTarget = Vector3.Distance(transform.position, target.transform.position); DebugExtension.DebugArrow(this.transform.position, dirToTarget * dstToTarget, Color.blue); } }
public static Vector3 CapsulePenetration(Vector3 position, CapsuleCollider collider, int layerMask) { var points = CalculateCapsuleColliderPoints(position, collider); Physics.OverlapCapsuleNonAlloc(points.point1, points.point2, collider.radius, tmpColliders, layerMask); Vector3 dir = Vector3.zero; Vector3 tmp = Vector3.zero; float tmpDist = 0; for (int i = 0; i < tmpColliders.Length; i++) { if (tmpColliders[i] == null) { break; } Physics.ComputePenetration( collider, points.point2, collider.transform.rotation, tmpColliders[i], tmpColliders[i].transform.position, tmpColliders[i].transform.rotation, out tmp, out tmpDist); DebugExtension.DebugArrow(points.point2 + Vector3.up, tmp * tmpDist, Color.blue, 5f); //DebugExtension.DebugPoint(collider.transform.position + tmp * tmpDist, Color.green, duration: 5f); dir += tmp * tmpDist; } return(position + dir); }
private void OnEnable() { this._lastSeenPosition = GameConstants.playerVariable.gameObject.transform.position + GameConstants.playerVariable.gameObject.transform.forward * this._searchRadius.Value; DebugExtension.DebugArrow(GameConstants.playerVariable.gameObject.transform.position, this._lastSeenPosition - GameConstants.playerVariable.gameObject.transform.position, Color.green, 5.0f); this._navMeshAgent.SetDestination(this._lastSeenPosition); this._elapsedTime = 0.0f; this._changePositionElapsedTime = 0.0f; this._lostTrack = false; }
protected override void OnFire(EWeaponState prevState) { base.OnFire(prevState); Transform shootTransform = MuzzleTransform; // Fire a ray cast from the player camera if (weaponOwner.CompareTag("Player")) { LNBPlayerCharacter playerOwner = weaponOwner.GetComponent <LNBPlayerCharacter>(); Transform eyeTran = playerOwner.GetEyeTransform(); // Fire ray int layerMask = 1 << LayerMask.GetMask("AimRay"); RaycastHit rayHit; Vector3 aimDir; Ray aimRay = new Ray(); aimRay.direction = eyeTran.forward; aimRay.origin = eyeTran.position; // If hit something if (Physics.Raycast(aimRay, out rayHit, MaxDistance, layerMask)) { aimDir = rayHit.point - shootTransform.position; } else { aimDir = aimRay.direction * MaxDistance; rayHit.distance = MaxDistance; } shootTransform.rotation = Quaternion.LookRotation(aimDir); #if DD_DEBUG // Aim trace DebugExtension.DebugArrow(aimRay.origin, aimRay.direction * rayHit.distance, Color.red, 1.0f); //Aim Direction DebugExtension.DebugArrow(shootTransform.position, aimDir, Color.green, 1.0f); #endif } // Spawn our projectile GameObject newProjObj = projectilePool.GetNextFree(); if (newProjObj) { newProjObj.SetActive(true); Projectile newProjectile = newProjObj.GetComponent <Projectile>(); if (!newProjectile) { Debug.Log("Instantiated something that's not a projectile! Add it in your prefab!"); return; } newProjectile.Launch(this, weaponOwner, MuzzleTransform); } }
private void OnDrawGizmos() { Vector3 circleCenter = transform.rotation * new Vector3(0.0f, 0.0f, WanderDistance) + transform.position; DebugExtension.DrawCircle(circleCenter, Vector3.forward, Color.green, WanderRadius); Debug.DrawLine(transform.position, target, debugColor); DebugExtension.DebugArrow(transform.position, transform.forward * WanderDistance, Color.red); }
// Update is called once per frame void Update() { DebugExtension.DebugPoint(debugPoint_Position, debugPoint_Color, debugPoint_Scale); DebugExtension.DebugBounds(new Bounds(new Vector3(10, 0, 0), debugBounds_Size), debugBounds_Color); DebugExtension.DebugCircle(new Vector3(20, 0, 0), debugCircle_Up, debugCircle_Color, debugCircle_Radius); DebugExtension.DebugWireSphere(new Vector3(30, 0, 0), debugWireSphere_Color, debugWireSphere_Radius); DebugExtension.DebugCylinder(new Vector3(40, 0, 0), debugCylinder_End, debugCylinder_Color, debugCylinder_Radius); DebugExtension.DebugCone(new Vector3(50, 0, 0), debugCone_Direction, debugCone_Color, debugCone_Angle); DebugExtension.DebugArrow(new Vector3(60, 0, 0), debugArrow_Direction, debugArrow_Color); DebugExtension.DebugCapsule(new Vector3(70, 0, 0), debugCapsule_End, debugCapsule_Color, debugCapsule_Radius); }
void RenderParticle(Particle particle) { float smoothingRadius = sph.smoothingRadius; float radius = sph.radius; Particle selectedParticle = sph.selectedDebugParticle; Vector3 pos = particle.position; Vector3 dir = particle.velocity.normalized; DebugExtension.DebugArrow(pos, dir * radius, Color.white, 0, false); if (particle == selectedParticle) { DebugExtension.DebugCircle(pos, Vector3.forward, Color.red, radius, 0, false); foreach (Particle neighbor in sph.grid.GetNearby(particle)) { DebugExtension.DebugCircle(neighbor.position, Vector3.forward, Color.magenta * 0.7f, radius * 1.5f, 0, false); } } else { DebugExtension.DebugCircle(pos, Vector3.forward, radius, 0, false); } Color radiusColor = new Color(0.5f, 0.5f, 0.5f, 0.4f); if (drawSmoothingRadius) { DebugExtension.DebugCircle(pos, Vector3.forward, radiusColor, smoothingRadius); } if (drawForce) { Color forceColor = new Color(1.0f, 0, 0, 0.4f); Vector3 force3 = new Vector3(particle.force.x, particle.force.y, 0); DebugExtension.DebugArrow(pos, force3 * radius * 1f, forceColor); } // Vector3 ul = new Vector3 (offset.x, size.y + offset.y); // Vector3 ur = new Vector3 (size.x + offset.x, size.y + offset.y); // Vector3 dl = new Vector3 (offset.x, offset.y); // Vector3 dr = new Vector3 (size.x + offset.x, offset.y); // Debug.DrawLine (ul, ur, Color.grey); // Debug.DrawLine (ur, dr, Color.grey); // Debug.DrawLine (dr, dl, Color.grey); // Debug.DrawLine (dl, ul, Color.grey); }
private void OnDrawGizmos() { if (steeringAgent != null && showGizmoArrows) { DebugExtension.DebugArrow(transform.position, desiredVelocity, Color.red); DebugExtension.DebugArrow(transform.position, steeringAgent.velocity, Color.blue); } if (EnemyTarget != null) { DebugExtension.DebugWireSphere(EnemyTarget.position, Color.green, FleeDistance); } }
public void GetDeltaA(float deltaC) { Vector2 va = ap.position - m.position; Vector2 vb = bp.position - m.position; //float zunit = FVector2.Cross(va,vb); float zunit = deltaC; Vector2 deltaA = FVector2.CrossUnitZ(va, zunit) * Mathf.Abs(deltaC) / 2f; Vector2 deltaB = FVector2.CrossUnitZ(vb, -zunit) * Mathf.Abs(deltaC) / 2f; DebugExtension.DebugArrow(ap.position, deltaA); DebugExtension.DebugArrow(bp.position, deltaB); }
public void Detach() { var otherPosition = fixedJoint.connectedBody.worldCenterOfMass; var ownPosition = rigidBody.worldCenterOfMass; var direction = (ownPosition - otherPosition).normalized; fixedJoint.enabled = false; fixedJoint.connectedBody = null; rigidBody.AddForce(direction * detachImpulse, ForceMode2D.Impulse); DebugExtension.DebugArrow(otherPosition, direction * 10f, Color.yellow, 0f, false); }
private void Update() { RaycastHit hit; if (Physics.Raycast(m_camera.ScreenPointToRay(Input.mousePosition), out hit, 100)) { //destination = hit.point; DebugExtension.DebugArrow(hit.point, Vector3.up, Color.red); if (Input.GetMouseButton(0)) { pncPlayer.destination = hit.point; } } }
private IEnumerable MoveResolver(BossActor actor, BossBehaviour.TargetType type) { BossBehaviour.Log(actor + " moves to " + type, actor); var mob = actor.Mobile; var targetPositionX = GetTargetPositionX(type, mob); var toTarget = targetPositionX - mob.BodyPosition.x; if (Mathf.Abs(toTarget) < _settings.CloseRangeThreshold) { foreach (var unused in WalkResolver(actor, targetPositionX)) { yield return(null); } } else if (Mathf.Abs(toTarget) < _settings.MidRangeThreshold) { BossBehaviour.Log(Time.frameCount + " actor will jump to targetX", actor); foreach (var unused in JumpAndWaitForCompletion(actor, toTarget)) { DebugExtension.DebugArrow(mob.BodyPosition.WithX(targetPositionX), Vector3.down); yield return(null); } } else { const float LongRangeWalkDistance = 2; var movementDirection = Mathf.Sign(toTarget); var walkTargetX = ClampPositionX(mob.BodyPosition.x + movementDirection * LongRangeWalkDistance); BossBehaviour.Log(Time.frameCount + " actor will first walk to walkTargetX", actor); foreach (var unused in WalkResolver(actor, walkTargetX)) { yield return(null); } BossBehaviour.Log(Time.frameCount + " then actor will jump to targetX", actor); foreach (var unused in JumpAndWaitForCompletion(actor, targetPositionX - mob.BodyPosition.x)) { DebugExtension.DebugArrow(mob.BodyPosition.WithX(targetPositionX), Vector3.down); yield return(null); } } }
protected void DebugAvailableDestinations() //TODO: Call this on BeginTurn. { GameManager gameManager = GameManager.instance; if (gameManager.WalkableTilemap != null) { foreach (Vector3Int availableDestination in AvailableDestinationTiles(gameManager.WalkableTilemap.Tilemap)) { var worldPos = gameManager.WalkableTilemap.Tilemap.CellToWorld(availableDestination) + new Vector3(0, .25f, 0); //Vector2Int adjustedAvailableDestination = gameManager.NodeIndexOnTileGrid(new Vector2Int(AvailableDestination.x, AvailableDestination.y)) DebugExtension.DebugArrow(worldPos, Vector3.back, Color.green, 0.01f); //Gizmos.DrawWireCube(availableDestination, Vector3.one); } } }
public void OnDebugUpdateRender() { if (m_vHeading.magnitude > 0) { DebugExtension.DebugArrow(m_vPos, m_vHeading * m_fBoundingRadius, Color.blue); } if (m_vSide.magnitude > 0) { DebugExtension.DebugArrow(m_vPos, m_vSide * m_fBoundingRadius, Color.red); } Gizmos.color = Color.black; DebugExtension.DebugCircle(m_vPos, m_fBoundingRadius); }
void Move() //Interpreting player controllers input { if (useMouseAndKeyboardInput) { movementDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")).normalized *movementSpeed; DebugExtension.DebugArrow(transform.position, movementDirection); float yVel = rb.velocity.y; rb.velocity = new Vector3(movementDirection.x, yVel, movementDirection.z); } if (useGamePadInput) { movementDirection = new Vector3(Input.GetAxis("Controller" + controllerNumber + " Left Stick Horizontal"), 0, -Input.GetAxis("Controller" + controllerNumber + " Left Stick Vertical")) * movementSpeed; DebugExtension.DebugArrow(transform.position, movementDirection); float yVel = rb.velocity.y; rb.velocity = new Vector3(movementDirection.x, yVel, movementDirection.z); } }
/// <summary> /// Tries to move rocket forward, explodes if it fails /// </summary> void Move() { RaycastHit hit; Vector3 movediff = rocketTransform.forward * moveSpeed * Time.deltaTime; if (isServer && Physics.Linecast(rocketTransform.position, rocketTransform.position + movediff, out hit, layerMask, QueryTriggerInteraction.Ignore)) { Rpc_Explode(hit.point); } rocketTransform.position += movediff; #region DEBUG if (DBG_Trail) { DebugExtension.DebugArrow(rocketTransform.position, movediff, new Color32(126, 52, 157, 255), DBG_time_trail, true); } #endregion }
private void DebugNavGrid() { Tilemap tilemap = WalkableTilemap.Tilemap; foreach (Vector3Int position in tilemap.cellBounds.allPositionsWithin) { Vector3 worldPosition = tilemap.CellToWorld(position) + new Vector3(0, .25f, 0); if ((displayGizmos) && tilemap.HasTile(position)) { DebugExtension.DebugArrow(worldPosition, Vector3.back, Color.blue, 10f); } else { DebugExtension.DebugArrow(worldPosition, Vector3.back, Color.red, 10f); } } }
// Update is called once per frame void Update() { Vector3 direction = transform.TransformDirection(new Vector3(intPosition.x - transform.position.x, 0, cohe)); if (debugArrow) { DebugExtension.DebugArrow(transform.position, direction, Color.blue); //DebugExtension.DrawCircle(transform.position,Vector3.up, Color.red, alig); DebugExtension.DebugCircle(transform.position, Vector3.up, Color.red, alig); DebugExtension.DebugPoint(transform.position + new Vector3(3 * transform.localScale.x / 2, -0.4f, 0), Color.yellow, 0.20f); DebugExtension.DebugPoint(transform.position + new Vector3(-3 * transform.localScale.x / 2, -0.4f, 0), Color.yellow, 0.20f); } GameObject[] allBoids; allBoids = GameObject.FindGameObjectsWithTag("Boids"); for (int i = 0; i < allBoids.Length; i++) { Vector3 foceBoids = Vector3.zero; ref GameObject obj = ref allBoids[i]; if (obj.transform.position.z > transform.position.z && obj.transform.position.z < transform.position.z + alig && obj.GetComponent <Rigidbody>().velocity.magnitude < this.GetComponent <Rigidbody>().velocity.magnitude) { RaycastBoids rB = obj.GetComponent <RaycastBoids>(); raycastObj objHit = rB.Raycast(widthObj); if (!objHit.right && transform.TransformDirection(objHit.ptRight - transform.position).x > 0) { foceBoids = transform.TransformDirection(objHit.ptRight - transform.position); } if (!objHit.left && transform.TransformDirection(objHit.ptLeft - transform.position).x < 0) { foceBoids = transform.TransformDirection(objHit.ptLeft - transform.position); } if (debugArrow) { //Debug.LogWarning(" magnitude: " + foceBoids.magnitude); DebugExtension.DebugArrow(transform.position, foceBoids.normalized, Color.cyan); } } direction += foceBoids * 10; }
private IEnumerable JumpAttackResolver(BossActor actor, BossBehaviour.TargetType type) { BossBehaviour.Log(actor + " jump attacks", actor); var mob = actor.Mobile; var targetPositionX = GetTargetPositionX(type, mob); // var targetPositionX = Mathf.Clamp( Player.BodyPosition.x, GetHotSpotPosition( TargetType.LeftCorner ).x, // GetHotSpotPosition( TargetType.RightCorner ).x ); var delta = targetPositionX - actor.Mobile.BodyPosition.x; foreach (var unused in JumpAttackAndWaitForCompletion(actor, delta)) { DebugExtension.DebugArrow(mob.BodyPosition.WithX(targetPositionX - delta), Vector3.up); DebugExtension.DebugArrow(mob.BodyPosition.WithX(targetPositionX), Vector3.down); yield return(null); } }
void Rotation() // Calculating angle between player joystick right stick declension { if (useMouseAndKeyboardInput) { camRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(camRay, out camHit, 5000, mouseTargetLayer)) { Vector3 relativeDirection = camHit.point - transform.position; Vector3 moveDirection = MightyUtilites.ClearY(relativeDirection).normalized; if (Vector3.Distance(MightyUtilites.ClearY(transform.position), MightyUtilites.ClearY(camHit.point)) > 0.3f) { Vector3 newRotation = Vector3.RotateTowards(transform.forward, moveDirection, 15.0f * Time.deltaTime, 0.0f).normalized; transform.rotation = Quaternion.LookRotation(newRotation, Vector3.up); lookDirection = newRotation; } } } if (useGamePadInput) { lookDirection = new Vector3(Input.GetAxis("Controller" + controllerNumber + " Right Stick Horizontal"), 0, -Input.GetAxis("Controller" + controllerNumber + " Right Stick Vertical")).normalized; if (lookDirection == Vector3.zero) { if (previousLookDirection == Vector3.zero) //for fixing Zero roation quat { transform.rotation = Quaternion.identity; } else { transform.rotation = Quaternion.LookRotation(previousLookDirection, Vector3.up); } } else { transform.rotation = Quaternion.LookRotation(lookDirection, Vector3.up); previousLookDirection = lookDirection; } DebugExtension.DebugArrow(transform.position, lookDirection * 10, Color.yellow); } }
public static void TakePicture(Transform parent, Bounds bounds, DirectionsEight dir, RenderTexture texture) { Camera.enabled = true; Camera.transform.parent = parent; Camera.targetTexture = texture; SpriteFacingControl.SetCameraPos(Camera, dir, main._viewOffset, 0f); if (main._debug) { DebugExtension.DebugArrow(Camera.transform.position, Camera.transform.forward, Color.blue, 5f); } main.Zoom(bounds); main.PositionBottom(parent.position); _canvasHackField.SetValue(null, null); Camera.Render(); _canvasHackField.SetValue(null, _canvasHackObject); Camera.Render(); Camera.enabled = false; //Camera.targetTexture = null; Camera.transform.parent = null; }
// Update is called once per frame protected override void OnUpdate() { if (bFiring == true) { if (fireDummyObject != null) { DebugExtension.DebugArrow(fireDummyObject.transform.position, transform.forward * 1.5f, Color.magenta); } m_fShootCoolTime += Time.deltaTime; if (WeaponInfo.fFiringTime < m_fShootCoolTime) { if (WeaponInfo.bAutoMode) { m_fShootCoolTime = 0; ShootAction(); } } } }
private static IEnumerable WalkResolver(BossActor actor, float targetPositionX) { var mob = actor.Mobile; const float MovementEpsilon = 0.1f; // set a timeout to prevent player from using properly timed attacks in order to block movement var walkSpeed = Boss1Settings.Instance.GroundedMovementSpeed; var distance = Mathf.Abs(mob.BodyPosition.x - targetPositionX); var duration = distance / walkSpeed; BossBehaviour.Log(Time.frameCount + " actor will walk to targetX", actor); while (Mathf.Abs(targetPositionX - mob.BodyPosition.x) > MovementEpsilon && duration > 0) { DebugExtension.DebugArrow(mob.BodyPosition.WithX(targetPositionX), Vector3.down); BossBehaviour.Log(Time.frameCount + " wait for actor to reach targetX", actor); duration -= Time.deltaTime; actor.DesiredMovement = Mathf.Sign(targetPositionX - mob.BodyPosition.x); yield return(null); } }
private void ApplyAlignmentBehavior() { for (int i = 0; i < boids.Count; i++) { Boid b = boids[i]; Vector3 avgDir = b.transform.forward; Vector3 dest; int count = 0; for (int j = 0; j < b.Neighbors.Count; j++) { Boid n = b.Neighbors[j]; Vector3 toNeighbor = n.transform.position - b.transform.position; float dist = toNeighbor.magnitude; if (dist < AlignmentRadius) { float falloffFactor = 1f - dist / AlignmentRadius; avgDir += n.transform.forward * falloffFactor; count++; } } if (count == 0) { continue; } avgDir /= count; dest = b.transform.position + avgDir; b.SteerTowards(dest, AlignmentStrength); if (Debug) { DebugExtension.DebugArrow(dest, avgDir * AlignmentStrength, Color.green, 0.1f); } } }
private void ApplySeparationBehavior() { for (int i = 0; i < boids.Count; i++) { Boid b = boids[i]; int count = 0; Vector3 avgDir = Vector3.zero; Vector3 dest; for (int j = 0; j < b.Neighbors.Count; j++) { Boid n = b.Neighbors[j]; Vector3 toNeighbor = n.transform.position - b.transform.position; float dist = toNeighbor.magnitude; if (dist < SeparationRadius) { float falloffFactor = 1f - dist / SeparationRadius; avgDir += toNeighbor * falloffFactor; count++; } } if (count == 0) { continue; } avgDir /= count; dest = b.transform.position + avgDir * -1f; b.SteerTowards(dest, SeparationStrength); if (Debug) { DebugExtension.DebugArrow(dest, avgDir * -1f * SeparationStrength, Color.yellow, 0.1f); } } }
void Update() { if (!tracking) { return; } if (WaypointReached) { if (++waypointIndex > waypointList.Count - 1) { waypointIndex = 0; //reset the index if it reaches the end of the list } } currentInput = new FrameInput(); currentInput.Reset(); //change to STAB mode and baromode = true //If we do not face the target, turn Vector3 proj = Vector3.ProjectOnPlane(NextWaypoint - drone.transform.position, Vector3.up); float angle = Vector3.Angle(proj, -Vector3.right); drone.setYaw = Vector3.Angle(proj, Vector3.back) < 90 ? -angle : angle; //If we are not on the same height as the target, adjust throttle currentInput.Throttle = Mathf.Clamp(pids[PIDs.THRUST].GetPID(NextWaypoint.y - drone.setAltitude), -1, 1); //pitch and roll to adjust the horizontal velocity vector //Vector3 addedVector = Vector3.ClampMagnitude(SecondNextWaypoint - NextWaypoint, 2.5f)*Mathf.Clamp01(1 - proj.magnitude/4); //Vector3 diff = (proj + 2*proj.normalized + addedVector); Vector3 diff = proj.normalized * 4; diff -= Vector3.ProjectOnPlane(drone.Velocity, Vector3.up); diff = drone.transform.InverseTransformDirection(diff); //clampLimit = Mathf.Clamp(10/diff.magnitude + .3f, -1, 1); currentInput.Pitch = Mathf.Clamp(pids[PIDs.PITCH].GetPID(diff.x), -clampLimit, clampLimit); currentInput.Roll = Mathf.Clamp(pids[PIDs.ROLL].GetPID(diff.z), -clampLimit, clampLimit); DebugExtension.DebugArrow(drone.transform.position, proj, Color.blue); DebugExtension.DebugArrow(drone.transform.position, drone.Velocity, Color.red); }
void OnDrawGizmosSelected() { Init(); DebugExtension.DebugArrow(transform.position, SimLightDir, Color.yellow); }