private void ApplyCohesionBehavior() { // Steer towards local average position for (int i = 0; i < boids.Count; i++) { Boid b = boids[i]; Vector3 avgPos = Vector3.zero; if (b.Neighbors.Count == 0) { continue; } for (int j = 0; j < b.Neighbors.Count; j++) { avgPos += b.Neighbors[j].transform.position; } avgPos /= b.Neighbors.Count; b.SteerTowards(avgPos, CohesionStrength); if (Debug) { DebugExtension.DebugPoint(avgPos, Color.blue, 0.1f); } } }
void Update() { foreach (var item in a) { item.Update(); } foreach (var item in navNodes) { //item.Update(); } //navNodes[58].DisplayNeighbours(0); if (knitDone) { var point = a[num1].DetermineIntersectionPoints(a[num2]); Debug.Log(a[num1].bounds.max.x); //Debug.Log(a[num1].bounds.min); //Debug.Log(a[num2].bounds.max); Debug.Log(a[num2].bounds.min.x); foreach (var item in point) { DebugExtension.DebugPoint(item, Color.magenta, .5f, 0); } AStarPath(start.transform.position, finish.transform.position); //pathfind from start to finish } }
void OnTriggerEnter(Collider other) { if (!enabled || !_canGenerateCollisions || _checkedColliders.Contains(other)) { return; } _checkedColliders.Add(other); var hitEntity = EntityController.GetEntity(UnityToEntityBridge.GetEntityId(other)); var entity = EntityController.GetEntity(EntityID); if (hitEntity == null || hitEntity.Id == EntityID) { return; } if (!CollisionCheckSystem.IsValidCollision(entity, _limitToEnemy, hitEntity, other, out var sourceNode, out var targetNode)) { return; } Debug.LogFormat("Trigger collision {0} {1} {2}", name, sourceNode.Entity.DebugId, targetNode.Entity.DebugId); var position = transform.position; var hitPnt = other.ClosestPointOnBounds(position); var hitNormal = (hitPnt - position).normalized; #if DEBUG DebugExtension.DebugPoint(hitPnt, Color.yellow, 1.5f, 4f); #endif hitEntity.Post(new CollisionEvent(entity, sourceNode, targetNode, hitPnt, hitNormal)); entity.Post(new PerformedCollisionEvent(sourceNode, targetNode, hitPnt, hitNormal)); }
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); }
private void Update() { if (Grid == null) { BuildGrid(); } if (DrawGridPoints) { foreach (var node in Grid.InnerGrid) { if (node.HasFlag(NodeFlags.Avoidance)) { DebugExtension.DebugWireSphere(Grid.ToWorldPosition(node.NavigableCenter), UnityColors.OrangeRed, 0.1f); } else if (node.HasFlag(NodeFlags.NearEdge)) { DebugExtension.DebugPoint(Grid.ToWorldPosition(node.NavigableCenter), UnityColors.Gray, 0.2f); } else if (node.HasFlag(NodeFlags.Navigation)) { DebugExtension.DebugPoint(Grid.ToWorldPosition(node.NavigableCenter), UnityColors.Blue, 0.2f); } } } }
void Rpc_Explode(Vector3 explosionpos) { //Explosion GameObject explosion = (GameObject)Instantiate(rocketExplosion, explosionpos, Quaternion.identity); Destroy(explosion, 1.0f); GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { player.GetComponent <PlayerCall>().Call_ExplosionDamage(explosionpos, rocketTeam, ownerIdentity); } //Trail rocketBits.transform.parent = null; rocketSmoke.transform.parent = null; em1.enabled = false; em2.enabled = false; Destroy(rocketBits, 0.4f); Destroy(rocketSmoke, 1.0f); #region DEBUG if (DBG_Explosion) { DebugExtension.DebugWireSphere(explosionpos, Color.blue, 0.05f, DBG_time_explosion, true); DebugExtension.DebugPoint(explosionpos, Color.red, 0.05f, DBG_time_explosion, true); DebugExtension.DebugWireSphere(explosionpos, Color.green, 2.0f, DBG_time_explosion, true); } #endregion Destroy(gameObject); //Destroys the rocket and everything still attached to it }
public void Trigger(ActionUsingNode node, string eventName) { var target = node.ActionEvent.Target; Entity spawnEntity; if (node.ActionEvent.SpawnPivot != null) { spawnEntity = World.Get <ProjectileSystem>().SpawnProjectile(node.ActionEvent.Action.Entity, Data, target, node.ActionEvent.SpawnPivot.position, node.ActionEvent.SpawnPivot.rotation); } else { var animData = node.Animator; var spawnPos = animData?.GetEventPosition ?? (node.Tr != null ? node.Tr.position : Vector3.zero); var spawnRot = animData?.GetEventRotation ?? (node.Tr != null ? node.Tr.rotation : Quaternion.identity); DebugExtension.DebugPoint(spawnPos, Color.blue, 1f, 1f); spawnEntity = World.Get <ProjectileSystem>().SpawnProjectile(node.ActionEvent.Action.Entity, Data, node.ActionEvent.Target, spawnPos, spawnRot); } if (spawnEntity != null) { if (node.ActionEvent.Action.Fx != null) { var afx = spawnEntity.Get <ActionFxComponent>(); if (afx != null) { afx.ChangeFx(node.ActionEvent.Action.Fx); } else { spawnEntity.Add(new ActionFxComponent(node.ActionEvent.Action.Fx)); } } } }
public void OnSceneGUI() { if (sim != null) { //debug particle index if (temp.debugParticleIndex) { for (int i = 0; i < sim.numberOfParticles(); i++) { Vector2 pos = temp.transform.localToWorldMatrix.MultiplyPoint3x4(sim.getParticle(i).Position); Handles.Label(pos, new GUIContent(i.ToString())); DebugExtension.DebugPoint(pos, Color.blue, 2f); } } //debug spring index if (temp.debugSpringIndex) { for (int i = 0; i < sim.numberOfSprings(); i++) { Vector2 midpt = (sim.getSpring(i).ParticleA.Position + sim.getSpring(i).ParticleB.Position) / 2f; midpt = temp.transform.localToWorldMatrix.MultiplyPoint3x4(midpt); GUIStyle st = new GUIStyle(); st.normal.textColor = Color.cyan - new Color(0f, 0f, 0f, 0.5f); Handles.Label(midpt, new GUIContent(i.ToString()), st); } } } }
private void Update() { foreach (Vector3 point in _points) { DebugExtension.DebugPoint(point); } ResetInput(); if (Vector3.Distance(transform.position, target.position) > .5f) { Vector2 targetDir = target.position - transform.position; float bestAngle = float.MaxValue; //TODO make smarter RegisteredMove bestMove = null; foreach (var move in registeredMoves) { if (!move.checkCondition()) { continue; } float angle = Vector2.Angle(targetDir, move.direction); if (angle < bestAngle) { bestAngle = angle; bestMove = move; } } bestMove?.doMove(bestMove.distanceToDuration(targetDir.magnitude)); //print(bestMove?.name); } }
public static SteeringOutput GetSteering(KinematicState ownKS, ref float targetOrientation, float wanderRate = 30f, float wanderRadius = 10f, float wanderOffset = 20f) { // change target orientation (change location of surrogate target on unit circle) targetOrientation += wanderRate * Utils.binomial(); // place surrogate target on circle of wanderRadius SURROGATE_TARGET.transform.position = Utils.OrientationToVector(targetOrientation) * wanderRadius; // place circle "in front" SURROGATE_TARGET.transform.position += ownKS.position + Utils.OrientationToVector(ownKS.orientation) * wanderOffset; // show some gizmos before returning Debug.DrawLine(ownKS.position, ownKS.position + Utils.OrientationToVector(ownKS.orientation) * wanderOffset, Color.black); DebugExtension.DebugCircle(ownKS.position + Utils.OrientationToVector(ownKS.orientation) * wanderOffset, new Vector3(0, 0, 1), Color.red, wanderRadius); DebugExtension.DebugPoint(SURROGATE_TARGET.transform.position, Color.black, 5f); // Seek the surrogate target return(Seek.GetSteering(ownKS, SURROGATE_TARGET)); }
public void ComputeVD3d() { List <DualSite3d> list = new List <DualSite3d>(); foreach (Site site in sites) { list.Add(site.ToDualSite()); } for (int i = 0; i < externalEdgePoints.Count; i++) { list.Add(externalEdgePoints[i].ToDualSite()); } VoronoiMesh <DualSite3d, TriangulationCellExt <DualSite3d>, VoronoiEdge <DualSite3d, TriangulationCellExt <DualSite3d> > > voronoiMesh = VoronoiMesh.Create <DualSite3d, TriangulationCellExt <DualSite3d> >(list); foreach (TriangulationCellExt <DualSite3d> vertex in voronoiMesh.Vertices) { Vector3 a = Vector3.zero; DualSite3d[] vertices = vertex.Vertices; foreach (DualSite3d dualSite3d in vertices) { a += dualSite3d.coord; } a *= 0.333333343f; DebugExtension.DebugPoint(a, Color.red, 1f, 0f, true); } }
public void Move(Vector2 velocityBias, bool isDash = false) { // DebugExtension.DebugArrow( BodyPosition, velocityBias, Color.blue ); // DebugExtension.DebugArrow( BodyPosition, CurrentVelocity, Color.red ); if (Time.deltaTime <= 0) { return; } var amount = (CurrentVelocity + velocityBias) * Time.deltaTime; var length = amount.magnitude; var direction = amount.normalized; var hit = Physics2D.CapsuleCast(BodyPosition, 0.6f * BodySize, CapsuleDirection2D.Vertical, 0, direction, length, _moveBlockingLayerMask | (isDash ? 0 : _dashableObstacleLayerMask)); if (hit.collider != null && !transform.IsAncestorOf(hit.collider.transform)) { DebugExtension.DebugPoint(hit.point, Color.yellow, 0.1f, 1); BodyPosition = hit.centroid; CancelHorizontalMovement(); } else { transform.Translate(direction * length); } CheckWallCollisions(isDash); }
private void CheckWallCollisions(bool isDash = false) { var filter = _wallCollisionContactFilter2D; if (!isDash) { filter.layerMask |= _dashableObstacleLayerMask; } if (_collisionCheckCollider.OverlapCollider(filter, _wallColliders) > 0) { if (transform.IsAncestorOf(_wallColliders[0].transform)) { return; } var distance2D = _collisionCheckCollider.Distance(_wallColliders[0]); DebugExtension.DebugPoint(distance2D.pointA, Color.red, 0.1f, 1); if (distance2D.distance > 0) { // Debug.LogError( "Should not be > 0" ); // Debug.Log( string.Format( "{0} - {1}", distance2D.normal, distance2D.distance ) ); } else { transform.Translate(distance2D.normal * distance2D.distance); CancelHorizontalMovement(); } } }
void OnCollisionEnter(Collision collision) { if (!enabled || !_canGenerateCollisions || _checkedColliders.Contains(collision.collider)) { return; } var other = collision.collider; _checkedColliders.Add(other); var hitEntity = EntityController.GetEntity(UnityToEntityBridge.GetEntityId(other)); var entity = EntityController.GetEntity(EntityID); if (hitEntity == null || hitEntity.Id == EntityID) { return; } if (!CollisionCheckSystem.IsValidCollision(entity, _limitToEnemy, hitEntity, other, out var sourceNode, out var targetNode)) { return; } var collisionPnt = collision.contacts[0]; var hitPnt = collisionPnt.point; var hitNormal = collisionPnt.normal; #if DEBUG DebugExtension.DebugPoint(hitPnt, Color.magenta, 1.5f, 4f); #endif hitEntity.Post(new CollisionEvent(entity, sourceNode, targetNode, hitPnt, hitNormal)); entity.Post(new PerformedCollisionEvent(sourceNode, targetNode, hitPnt, hitNormal)); }
private void Update() { foreach (var item in surfaces) { //Debug.DrawLine(item.Center, item.Center + item.Normal); DebugExtension.DebugPoint(item.ClosestPoint(point.transform.position), Color.green, .1f); } }
private void OnDrawGizmos() { for (float pct = 0.0f; pct <= 1.0f; pct += 0.001f) { Vector3 point = Spline.GetPointAtPct(pct); DebugExtension.DebugPoint(point); } }
// Cast a line from A to B, checking for collisions with other entities. public IEnumerable <LineCastResult> LineCastAll(DVector3 start, DVector3 end, int ignoreTeam = -1) { var start2d = new DVector2(start.x, start.z); var end2d = new DVector2(end.x, end.z); foreach (Collider c in colliders) { if (c.entity.team == ignoreTeam) { continue; } var position2d = new DVector2(c.entity.position.x, c.entity.position.z); DVector2 result; // FIXME: Need to adjust positions to correct for wrap. // FIXME: Some cases still not handled properly. // // _______________ // | / | // ---X----------- // / // / // O // / // / // Circle intersects at O, which is a miss, but a real intersect happens at X. if (Utility.IntersectLineCircle(position2d, c.radius, start2d, end2d, out result)) { // Possible hit, work out the correct 3D position at the intersect. var result3d = new DVector3(result.x, start.y, result.y); var a = result3d - start; var bhat = (end - start).normalized; var ab = DVector3.Dot(a, bhat); var intersectPoint = start + bhat * ab; var height = intersectPoint.y; var bottom = c.entity.position.y; var top = bottom + c.height; Logger.Log("result3d: {0} a: {1} bhat: {2} ab: {3} height: {4} bottom: {5} top:{6}", result3d, a, bhat, ab, height, bottom, top); DebugExtension.DebugPoint((UnityEngine.Vector3)intersectPoint, UnityEngine.Color.blue, 10, 10); UnityEngine.Debug.DrawLine((UnityEngine.Vector3)start, (UnityEngine.Vector3)end, UnityEngine.Color.green, 10); UnityEngine.Debug.DrawLine((UnityEngine.Vector3)start, (UnityEngine.Vector3)result3d, UnityEngine.Color.green, 10); if (bottom <= height && height <= top) { var r = new LineCastResult(); r.entity = c.entity; r.position = intersectPoint; yield return(r); } } } }
// 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); }
private void Update() { for (int i = 0; i < cells.Count; i++) { if (cells[i] != PathFinder.InvalidCell) { Vector3 position = Grid.CellToPosCCF(cells[i], Grid.SceneLayer.Background); DebugExtension.DebugPoint(position, 1f, 0f, true); } } }
public bool CheckGround(out Collider2D col, out Vector2 normal, bool snap = true, bool ignorePassThrough = false) { var layerMask = _groundLayerMask; if (!ignorePassThrough) { layerMask |= _passThroughLayerMask; } var frontGroundOffset = 0.2f * BodySize.y; var backGroundOffset = 0.2f * BodySize.y; var frontHit = Physics2D.Raycast( BodyPosition + 0.25f * BodySize.x * Direction * Vector2.right + (0.5f * BodySize.y - frontGroundOffset) * Vector2.down, Vector2.down, frontGroundOffset + RailStickiness, layerMask); var backHit = Physics2D.Raycast( BodyPosition - 0.25f * BodySize.x * Direction * Vector2.right + (0.5f * BodySize.y - backGroundOffset) * Vector2.down, Vector2.down, backGroundOffset + RailStickiness, layerMask); if (backHit.collider == null && frontHit.collider == null) { col = null; normal = Vector2.zero; return(false); } var selectedHit = backHit; if (frontHit.collider != null) { selectedHit = frontHit; } DebugExtension.DebugPoint(selectedHit.point, 0.1f, 1); normal = selectedHit.normal; col = selectedHit.collider; if (snap) { var tangent = normal.Perp(); var distance = Mathf.Abs(tangent.PerpDot(BodyPosition - selectedHit.point)); BodyPosition = BodyPosition - normal * (distance - 0.5f * BodySize.y); CancelMovementAlongAxis(normal); } return(true); }
// Update is called once per frame void FixedUpdate() { if (targets.Count > 0) { for (int i = 0; i < targets.Count; i++) { float force = targets[i].velocity.sqrMagnitude * 0.001f; sp.ApplyForce(force); targets[i].AddForce(-sp.Di * force); DebugExtension.DebugPoint(sp.Pos3, Color.red, 20f, 0.5f, false); } } }
private static CollisionEvent?CheckRayList(Entity originEntity, int limit, bool limitEnemy) { for (int i = 0; i < limit; i++) { if (originEntity.IsDestroyed()) { return(null); } var hit = _rayHits[i]; Entity hitEntity = EntityController.GetEntity(UnityToEntityBridge.GetEntityId(hit.collider)); bool isEnvironment = hitEntity == null && hit.transform.IsEnvironment(); #if DEBUG_RAYCAST Color pointColor = Color.white; if (isEnvironment) { pointColor = Color.green; } else if (hit.transform.CompareTag(StringConst.TagInvalidCollider)) { pointColor = Color.magenta; } else if (hitEntity != null) { pointColor = Color.red; } DebugExtension.DebugPoint(_rayHits[i].point + (Vector3.up * (i * 0.1f)), pointColor, 0.25f, 2.5f); #endif if (isEnvironment) { #if DEBUG DebugLog.Add(originEntity.DebugId + " hit environment " + _rayHits[i].transform.name); #endif originEntity.Post(new EnvironmentCollisionEvent(originEntity, _rayHits[i].point, _rayHits[i].normal)); return(null); } if (hitEntity == null) { continue; } if (IsValidCollision(originEntity, limitEnemy, hitEntity, _rayHits[i].collider, out var sourceNode, out var targetNode)) { var ce = new CollisionEvent(originEntity, sourceNode, targetNode, _rayHits[i].point, _rayHits[i].normal); hitEntity.Post(ce); originEntity.Post(new PerformedCollisionEvent(sourceNode, targetNode, _rayHits[i].point, _rayHits[i].normal)); return(ce); } } return(null); }
public bool CheckCeiling(out Vector2 normal) { var hit = Physics2D.Raycast(BodyPosition, Vector2.up, 0.5f * BodySize.y + RayCastEpsilon, _groundLayerMask); normal = hit.normal; if (hit.collider != null) { DebugExtension.DebugPoint(hit.point, 0.1f, 1); CancelVerticalMovement(); return(true); } return(false); }
void Update() { for (int i = 0; i < surfaces.Count; i++) { DebugExtension.DebugPoint(surfaces[i].ClosestPoint(point.transform.position), Color.green, .1f); //DebugExtension.DebugArrow(surfaces[i].Center, surfaces[i].Normal*.5f); } //int j = 0; //DebugExtension.DebugPoint(surfaces[j].P[0], Color.red, .1f); //DebugExtension.DebugPoint(surfaces[j].P[1], Color.yellow, .1f); //DebugExtension.DebugPoint(surfaces[j].P[2], Color.blue, .1f); //DebugExtension.DebugPoint(surfaces[j].ClosestPoint(point.transform.position), Color.red, .1f); DebugExtension.DebugLocalCube(obj.transform, new Vector3(1.0f, 1.0f, 1.0f), Color.cyan); }
private void AdjustHeight() { Vector3 groundLinecastStartPosition = Vector3.up + new Vector3(transform.position.x, stick.TransformVector(new Vector3(0f, 0f, stickMinZoom)).y, transform.position.z); Vector3 groundLinecastEndPosition = new Vector3(transform.position.x, 0f, transform.position.z) + Vector3.down; RaycastHit groundHit; Debug.DrawLine(groundLinecastStartPosition, groundLinecastEndPosition); if (Physics.Linecast(groundLinecastStartPosition, groundLinecastEndPosition, out groundHit)) { DebugExtension.DebugPoint(groundHit.point); _hit = groundHit; float difference = Mathf.Abs(transform.position.y - groundHit.point.y); transform.position = Vector3.Slerp(transform.position, groundHit.point, cameraElevationSpeed * difference * Time.deltaTime); } }
private void DebugDrawValidCells() { Color color = Color.white; int cellCount = Grid.CellCount; for (int i = 0; i < cellCount; i++) { for (int j = 0; j < 10; j++) { NavType nav_type = (NavType)j; if (NavTable.IsValid(i, nav_type) && DrawNavTypeCell(nav_type, ref color)) { DebugExtension.DebugPoint(NavTypeHelper.GetNavPos(i, nav_type), color, 1f, 0f, false); } } } }
// 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 void OnCollisionEnter(Collision collision) { if (!_crashOnCollision) { return; } if (((1 << collision.gameObject.layer) & _collisionMask) == 0) { return; } ContactPoint[] contactPoints = new ContactPoint[collision.contactCount]; collision.GetContacts(contactPoints); foreach (var contactPoint in contactPoints) { DebugExtension.DebugPoint(contactPoint.point, Color.black, duration: 10f); Debug.DrawLine(contactPoint.point, contactPoint.point + contactPoint.normal, Color.grey, duration: 10f); //Debug.DrawLine(contactPoints[0].point, contactPoints[0].point + relativeVelocity, Color.red, duration: 10f); } var relativeVelocity = collision.relativeVelocity; var force = relativeVelocity.magnitude; var normal = contactPoints[0].normal; //var impulse = collision.impulse.magnitude; var dotFront = Vector3.Dot(normal, -transform.forward); var dotUp = Vector3.Dot(normal, transform.up); //print($"up: {dotUp}; front: {dotFront}; force: {force}; impulse: {impulse}"); float forceWeight = Utility.RemapNumberClamped(force, _forceMin, _forceMax, 0f, 1f); float upWeight = Utility.RemapNumberClamped(dotUp, _upMin, _upMax, 0, -1f); float frontWeight = Utility.RemapNumber(dotFront, _frontMin, _frontMax, 0f, 1f); float sum = forceWeight + upWeight + frontWeight; //print($"upW: {upWeight}; frontW: {frontWeight}; forceW: {forceWeight}; sum: {sum}"); if (sum > _sumThresold) { Crash(-relativeVelocity); } }
private void HandleCameraClip() { Vector3[] outCorners = new Vector3[4]; Camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), Camera.nearClipPlane, Camera.MonoOrStereoscopicEye.Mono, outCorners); outCorners.ToList().ForEach(c => DebugExtension.DebugPoint(stick.TransformVector(c) + stick.position, 0.1f)); foreach (Vector3 point in outCorners) { Debug.DrawLine(Camera.transform.position, stick.TransformVector(point) + stick.position); if (Physics.Linecast(stick.TransformVector(point) + stick.position, Camera.transform.position)) { AdjustZoom(-0.01f); } } Debug.DrawLine(Camera.transform.position, Camera.transform.position + Camera.transform.forward * Camera.nearClipPlane); if (Physics.Linecast(Camera.transform.position + Camera.transform.forward * Camera.nearClipPlane, Camera.transform.position)) { AdjustZoom(-0.01f); } }
void UpdateSearching() { bool reachedDestination = MoveAlongPath(searchSpeed); if (reachedDestination) { if (currentSearchIndex == searchPoints.Length - 1) { StartPatrolling(); } else { SetDestination(searchPoints[++currentSearchIndex], 0.5f); } } foreach (Vector2 p in searchPoints) { DebugExtension.DebugPoint(p, Color.red, 0.2f); } }