// Draw out the path calculated by the agent void Update() { // Is the path calculated? if (path != null) { // Corners refers to the nodes that Unity generated through A* Vector3[] corners = path.corners; // Has generated corners for the path? if (corners.Length > 0) { // Store the last corner into target pos Vector3 targetPos = corners[corners.Length - 1]; // Draw the target GizmosGL.color = new Color(1, 0, 0, 0.3f); GizmosGL.AddSphere(targetPos, targetRadius * 2f); // Calculate distance from agent to target float distance = Vector3.Distance(transform.position, targetPos); // Is the distance greater than target radius? if (distance >= targetRadius) { GizmosGL.color = Color.cyan; for (int i = 0; i < corners.Length - 1; i++) { Vector3 nodeA = corners[i]; Vector3 nodeB = corners[i + 1]; GizmosGL.AddLine(nodeA, nodeB, 0.1f, 0.1f); GizmosGL.AddSphere(nodeB, 1f); Gizmos.color = Color.red; } } } } }
public override Vector3 GetForce() { // SET force to vector3.zero Vector3 force = Vector3.zero; // IF target == null if (target == null) { // return force return(force); } // LET desiredForce = target position - transform position Vector3 desiredForce = target.position - transform.position; // -(target.position - transform.position) = - target.position + transform.position // IF desiredForce magnitude > stoppingDistance if (desiredForce.magnitude > StoppingDistance) { // desiredForce = desiredForce normalized x weighting desiredForce = desiredForce.normalized * weighting; // force = desiredForce - owner.velocity force = desiredForce - owner.velocity; } #region GizmosGL GizmosGL.color = Color.green; GizmosGL.AddLine(transform.position, transform.position + desiredForce, 0.1f, 0.1f); #endregion // Return force return(force); }
// Move the selected piece if one is selected void MoveSelection() { // Check if a place has been selected if (selectedTower != null) { // Create a new ray from the camera Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GizmosGL.color = Color.yellow; GizmosGL.AddLine(ray.origin, ray.origin + ray.direction * rayDistance, 0.1f, 0.1f); RaycastHit hit; Vector3 hitPoint = Vector3.zero; // Raycast to only hit objects that aren't towers if (Physics.Raycast(ray, out hit, rayDistance, ~selectionIgnoreLayer)) { // Obtain the hit point GizmosGL.color = Color.blue; GizmosGL.AddSphere(hit.point, 0.5f); hitPoint = hit.point; // Move the tower to position Vector3 piecePos = hit.point + Vector3.up * pieceHeight; selectedTower.transform.position = piecePos; } // Check if mouse button is released if (Input.GetMouseButtonUp(0)) { // Drop the piece on hitPoint selectedTower.transform.position = hitPoint; // Deselect the piece selectedTower = null; } } }
// Check if we are selecting a piece void CheckSelection() { if (selectedPiece) { if (selectedPiece != null) { return; } } // Creating a ray from camera mouse position to world Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GizmosGL.color = Color.red; GizmosGL.AddLine(ray.origin, ray.origin + ray.direction * rayDistance, 0.1f, 0.1f); // Check if the player hits the mouse button if (Input.GetMouseButtonDown(0)) { RaycastHit hit; // Cast a ray to detect piece if (Physics.Raycast(ray, out hit, rayDistance)) { // Set the selected piece to be the hit object selectedPiece = hit.collider.GetComponent <Piece>(); // If the user did not hit a piece if (selectedPiece == null) { Debug.Log("Cannot pick up object: " + hit.collider.name); } } } }
// Move the selected piece if one is selected void MoveSelection() { // Check if a piece has been selected if (selectedPiece != null) { // Create a new ray from the camera Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GizmosGL.color = Color.yellow; GizmosGL.AddLine(ray.origin, ray.origin + ray.direction * rayDistance, 0.1f, 0.1f); RaycastHit hit; // Raycast to only hit objects that aren't pieces if (Physics.Raycast(ray, out hit, rayDistance, ~selectionIgnoreLayer)) { hitPoint = hit.point; // Obtain the hit point GizmosGL.color = Color.blue; GizmosGL.AddSphere(hit.point, 0.5f); // Move the piece to position Vector3 piecePos = hit.point + Vector3.up * pieceHeight; selectedPiece.transform.position = piecePos; } if (Input.GetMouseButtonUp(0)) { // Drop the piece to hitpoint Piece piece = selectedPiece.GetComponent <Piece>(); board.DropPiece(piece, hitPoint); // Deselect the piece selectedPiece = null; } } }
void Update() { // is the path calculated?i if (path != null) { Vector3[] corners = path.corners; if (corners.Length > 0) { Vector3 targetPos = corners[corners.Length - 1]; // Draw the target Gizmos.color = new Color(1, 0, 0, 0.3f); //. calculate distance from agent to target float distance = Vector3.Distance(transform.position, targetPos); // If distance is greater than the radius if (distance >= targetRadius) { Gizmos.color = Color.cyan; // Draw lines between nodes for (int i = 0; i < corners.Length - 1; i++) { Vector3 nodeA = corners[i]; Vector3 nodeB = corners[i + 1]; GizmosGL.AddLine(nodeA, nodeB, 0.1f, 0.1f); GizmosGL.AddSphere(nodeB, 1f); GizmosGL.color = Color.blue; } } } } }
public override Vector3 GetForce() { Vector3 force = Vector3.zero; Vector3 centerPoint = transform.position + rayOffset; Vector3 ahead = centerPoint + transform.forward.normalized * maxSeeDistance; Ray ray = new Ray(centerPoint, transform.forward); //Line line = GizmosGL.AddLine(ray.origin, ray.origin + ray.direction * maxSeeDistance); //line.color = Color.cyan; RaycastHit hit; if (Physics.Raycast(ray, out hit, maxSeeDistance, collisionLayer)) { //line.color = Color.red; //Vector3 center = hit.point + -hit.normal * intersectForce; Vector3 center = hit.collider.transform.position; Vector3 direction = ahead - center; Vector3 avoidance = direction.normalized * maxAvoidForce; avoidance *= maxAvoidForce; Collider col = hit.collider; Bounds bounds = col.bounds; GizmosGL.AddCube(center, bounds.size * 2); GizmosGL.AddSphere(center, 0.5f); GizmosGL.AddLine(transform.position, transform.position + avoidance * 10f, 1, 1, Color.red, Color.red); Vector3 desiredVelocity = avoidance.normalized; force = Vector3.zero; force += desiredVelocity; } return(force); }
void CheckSelection() { // SET ray to ray from camera Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GizmosGL.AddLine(ray.origin, ray.origin + ray.direction * rayDistance, 0.1f, 0.1f, Color.red, Color.blue); // SET hit to new RaycastHit RaycastHit hit = new RaycastHit(); // IF Physics.Raycast() and pass ray, out hit, rayDistance, selectionLayer if (Physics.Raycast(ray, out hit, rayDistance, selectionLayer)) { // CALL GizmoGL.AddSphere() and pass hit.point, 5f, Quaternion.identity, ay color GizmosGL.AddSphere(hit.point, 5f, Quaternion.identity, Color.red); // IF user clicked left mouse button if (Input.GetMouseButtonDown(0)) { animator.SetFloat("moveSpeed", 1); // SET selectedTarget to hit.collider.transform selectedTarget = hit.collider.transform; // CALL ApplySelection ApplySelection(); } } }
void Update() // Draw out path calculated by agent { if (path != null) { Vector3[] corners = path.corners; if (corners.Length > 0) { Vector3 targetPos = corners[corners.Length - 1]; GizmosGL.color = new Color(1, 0, 0, 0.3f); GizmosGL.AddSphere(targetPos, targetRad * 2); float dist = Vector3.Distance(transform.position, targetPos); if (dist >= targetRad) { GizmosGL.color = Color.cyan; for (int i = 0; i < corners.Length - 1; i++) { Vector3 nodeA = corners[i]; Vector3 nodeB = corners[i + 1]; GizmosGL.AddLine(nodeA, nodeB, 0.1f, 0.1f); GizmosGL.AddSphere(nodeB, 1f); GizmosGL.color = Color.red; } } } } }
// Draws out the path the NPC follows void OnDrawGizmos() { // The color of the Gizmos will be red Gizmos.color = Color.red; // what to do if the path is not calculated if (path != null) { Vector3[] corners = path.corners; if (corners.Length > 0) { Vector3 targetPos = corners[corners.Length - 1]; GizmosGL.color = new Color(1, 0, 0, 0.3f); GizmosGL.AddSphere(targetPos, targetRadius); // Calculate the distance from the agent to the target float distance = Vector3.Distance(transform.position, targetPos); // Checks if the distance is greater or equal to the target Radius if (distance >= targetRadius) { Gizmos.color = Color.cyan; // Draw lines between nodes for (int i = 0; i < corners.Length - 1; i++) { Vector3 nodeA = corners[i]; Vector3 nodeB = corners[i + 1]; GizmosGL.AddLine(nodeA, nodeB, 0.1f, 0.1f); GizmosGL.AddSphere(nodeB, 1f); GizmosGL.color = Color.red; } } } } }
public override Vector3 GetForce() { // SET force to Vector3 zero Vector3 force = Vector3.zero; // IF target is null, return force if (target == null) { return(force); } // SET desiredForce Vector3 desiredForce = target.position - transform.position; #region GizmosGL GizmosGL.color = Color.white; GizmosGL.AddLine(transform.position, target.position, .1f, .1f); GizmosGL.color = new Color(1, 0.325f, 0.305f, 1); GizmosGL.AddSphere(target.position, stoppingDistance * 2f); #endregion // Check if the direction is valid if (desiredForce.magnitude > stoppingDistance) { // Calculate force desiredForce = desiredForce.normalized * weighting; force = desiredForce - owner.velocity; } // Return the force! return(force); }
private void OnDrawGizmos() { Gizmos.color = Color.red; if (path != null) { Vector3[] corners = path.corners; if (corners.Length > 0) { Vector3 targetPos = corners[corners.Length - 1]; // Draw target Gizmos.color = Color.magenta; Gizmos.DrawWireSphere(targetPos, targetRadius); GizmosGL.color = new Color(1, 0, 0, 0.3f); GizmosGL.AddSphere(targetPos, targetRadius); float distance = Vector3.Distance(transform.position, targetPos); if (distance >= targetRadius) { GizmosGL.color = Color.cyan; for (int i = 0; i < corners.Length - 1; i++) { GizmosGL.AddLine(corners[i], corners[i + 1], 0.1f, 0.1f); GizmosGL.AddSphere(corners[i + 1], 1f); GizmosGL.color = Color.red; } } } } }
public override Vector3 GetForce() { // LET force = Vector3.zero force = Vector3.zero; // IF target == null if (target == null) { // return force return(force); } // LET desiredForce = target.position - transform.position Vector3 desiredForce = target.position - transform.position; //IF desiredForce.magnitude > stoppingDistance if (desiredForce.magnitude > stoppingDistance) { // SET desiredForce = desiredForce.normalized * weighting desiredForce = desiredForce.normalized * weight; // SET force = desiredForce - owner.velocity force = desiredForce - owner.velocity; } #region GizmosGL GizmosGL.color = Color.red; GizmosGL.AddLine(transform.position, transform.position + force); GizmosGL.color = Color.blue; GizmosGL.AddLine(transform.position, transform.position + desiredForce); #endregion // Return the force... luke return(force); }
public override Vector3 GetForce() { Vector3 force = Vector3.zero; if (path != null && path.Count > 0) { Vector3 currentPosition = path[currentNode].position; if (Vector3.Distance(transform.position, currentPosition) <= nodeRadius) { currentNode++; if (currentNode <= path.Count) { currentNode = path.Count - 1; } } force = Seek(currentPosition); #region GISMO Vector3 previousPosition = path[0].position; foreach (Node node in path) { GizmosGL.AddSphere(node.position, grap.nodeRadius, Quaternion.identity, Color.blue); GizmosGL.AddLine(previousPosition, node.position, 0.01f, 0.01f, Color.yellow); previousPosition = node.position; } #endregion } return(force); }
public override Vector3 GetForce() { Vector3 force = Vector3.zero; float randX = Random.Range(0, 0x7fff) - (0x7fff / 2); float randZ = Random.Range(0, 0x7fff) - (0x7fff / 2); #region Calculate RandomDir // Create the randomdir randomDir = new Vector3(randX, 0, randZ); // Normalize randomDir randomDir.Normalize(); //Apply jitter to it randomDir *= jitter; #endregion #region Calculate TargetDir // Offset targetDir with randomDir; targetDir += randomDir; // Normalize the targetDir; targetDir.Normalize(); // Apply radius to it targetDir *= radius; #endregion // Get position of point Vector3 seekPos = transform.position + targetDir; // Offset the seek position seekPos += transform.forward * offset; #region GizmosGL GizmosGL.color = Color.red; GizmosGL.AddCircle(seekPos + Vector3.up * 0.2f, 0.5f, Quaternion.LookRotation(Vector3.down)); Vector3 offsetPos = transform.position + transform.forward * offset; GizmosGL.color = Color.blue; GizmosGL.AddCircle(offsetPos + Vector3.up * 0.1f, radius, Quaternion.LookRotation(Vector3.down)); GizmosGL.color = Color.cyan; GizmosGL.AddLine(transform.position, offsetPos, 0.1f, 0.1f); #endregion // Calculate direction Vector3 direction = seekPos - transform.position; Vector3 desiredPos = Vector3.zero; // Check if direction is valid if (direction != Vector3.zero) // or direction.magnitude != 0 { // Apply a weighting to the direction desiredPos = direction.normalized * weighting; // Apply the force force = desiredPos - owner.velocity; } return(force); }
public override void Debug() { GizmosGL.color = Color.red; Vector3 originalPos = new Vector3(minDistance, 0, 0); Vector3 playerPos = transform.position; GizmosGL.AddLine(originalPos, originalPos + Vector3.right * minDistance); GizmosGL.AddLine(originalPos, playerPos, 0.35f, 0.35f); }
public override void Debug() { GizmosGL.color = Color.red; Vector3 originalPos = new Vector3(0, originY, 0); Vector3 playerPos = transform.position; GizmosGL.AddLine(originalPos, originalPos + Vector3.up * minHeight); GizmosGL.AddLine(originalPos, playerPos, 0.35f, 0.35f); }
// Update is called once per frame void FixedUpdate() { GizmosGL.AddRing(ring.position, ring.innerRadius, ring.outerRadius, Quaternion.Euler(ring.rotation), ring.scale, ring.segments, ring.color); GizmosGL.AddArc(arc.position, arc.radius, arc.halfAngle, arc.rotation, arc.segments, arc.color); GizmosGL.AddSphere(sphere.position, sphere.radius, sphere.rotation, sphere.color); GizmosGL.AddSquare(square.position, square.scale, square.rotation); GizmosGL.AddCircle(circle.position, circle.radius, Quaternion.identity, circle.segments, circle.color); GizmosGL.AddCube(cube.position, cube.scale, cube.rotation); GizmosGL.AddCube(cube.position, cube.scale, cube.rotation); GizmosGL.AddCylinder(cylinder.position, cylinder.radius, cylinder.scale, cylinder.rotation, cylinder.halfLength, cylinder.segments, cylinder.color); GizmosGL.AddLine(line.start, line.end, line.startWidth, line.endWidth, line.startColor, line.endColor); }
public override void Debug() { GizmosGL.color = Color.red; Vector3 originalPos = new Vector3(0, originalY, 0); Vector3 playerPos = transform.position; // Draw the min height the player needs to jump to GizmosGL.AddLine(originalPos, originalPos + Vector3.up * minHeight); // Draw the player's current height GizmosGL.AddLine(originalPos, playerPos, 0.35f, 0.35f); }
// Calculates force for behaviour public override Vector3 GetForce() { // SET force to zero Vector3 force = Vector3.zero; // IF path is not null AND path count is greater than zero if (path != null && path.Count > 0) { // SET currentPos to path[currentNode] position Vector3 currentPos = path[currentNode].position; // IF distance between transform's position and currentPos is less than or equal to nodeRadius // IF (distance between transform's position and currentPos) <= (nodeRadius) // IF (Vector3.Distance(transform.position, currentPos) <= (nodeRadius) if (Vector3.Distance(transform.position, currentPos) <= nodeRadius) { // Increment currentNode currentNode++; // IF currentNode is greater than or equal to path.count if (currentNode > path.Count) { // SET currentNode to path.Count -1 currentNode = path.Count - 1; } } // SET force to Seek() and pass currentPos force = Seek(currentPos); #region GIZMOS // SET prevPosition to path[0].position Vector3 prevPosition = path[0].position; // FOREACH node in path foreach (Node node in path) { // CALL GizmoGL.AddSphere() and pass node's position, graph's nodeRadius, identity, any colour GizmosGL.AddSphere(node.position, graph.nodeRadius, Quaternion.identity, Color.green); // CALL GizmoGL.AddLine() and pass prev, node's position, 0.1f, 0.1f, any color, any color GizmosGL.AddLine(prevPosition, currentPos, 0.1f, 0.1f, Color.red, Color.blue); // SET prev to node's positio prevPosition = node.position; } #endregion } #endregion // RETURN force return(force); }
// Update is called once per frame public void Move(float inputH, float inputV) { Vector3 localForce = new Vector3(inputH, 0, inputV); force = Quaternion.LookRotation(Camera.main.transform.up, -body.Gravity) * localForce; GizmosGL.AddLine(transform.position, transform.position + force, 0.3f, 0.3f, Color.blue, Color.blue); rigid.AddForce(force * speed); // If velocity reaches higher than max velocity if (rigid.velocity.magnitude > maxVelocity) { // Cap that shit bish rigid.velocity = rigid.velocity.normalized * maxVelocity; } }
private void Update() { //if (Input.GetKey(KeyCode.R)) //{ // Line spawn = GizmosGL.AddLine(Vector3.zero, Vector3.one * 10f, 0.1f, 0.1f); //} for (int i = 0; i < 500; i++) { Vector3 pos = new Vector3(Mathf.Sin(i) * 9f, i * 0.1f, Mathf.Cos(i) * 9f); Cube spawn = GizmosGL.AddCube(pos); spawn.isRigidbodyEnabled = true; spawn.isCollisionEnabled = true; //spawn.rigidbody.useGravity = false; //spawn.isCollisionEnabled = true; spawn.color = Color.Lerp(Color.red, Color.blue, (float)i / 800f); } Vector3 prevPos = transform.position; for (int i = 0; i < 200; i++) { Vector3 pos = prevPos + new Vector3(Mathf.Tan(i) * 2f, i * 0.1f); Line line = GizmosGL.AddLine(prevPos, pos, 1f, 1f); line.color = Color.Lerp(Color.red, Color.blue, (float)i / 200f); line.startColor = Color.red; line.endColor = Color.blue; line.startWidth = 0.1f; line.endWidth = 0.1f; prevPos = pos; } for (int i = 0; i < 200; i++) { Circle spawn = GizmosGL.AddCircle(new Vector3(Mathf.Sin(i) * 2f, i * 0.1f), circle.radius, Quaternion.identity, circle.segments, circle.color); spawn.isRigidbodyEnabled = true; spawn.name = "FixedUpdate - Circle"; } for (int i = 0; i < 200; i++) { Square spawn = GizmosGL.AddSquare(new Vector3(Mathf.Sin(i) * 2f, i * 1f), new Vector2(1, 1)); spawn.color = Color.blue; //spawn.isRigidbodyEnabled = true; spawn.name = "FixedUpdate - Circle"; } }
// Update is called once per frame void Update() { GizmosGL.AddCircle(circle.position, circle.up, circle.radius, circle.segments, circle.color); GizmosGL.AddSquare(square.position, square.up, square.scale, square.color); GizmosGL.AddCube(cube.position, cube.scale, cube.color); GizmosGL.AddSphere(sphere.position, sphere.radius, sphere.rows, sphere.columns, sphere.color, sphere.longMin, sphere.longMax, sphere.latMin, sphere.latMax); GizmosGL.AddCylinder(cylinder.position, cylinder.up, cylinder.radius, cylinder.halfLength, cylinder.segments, cylinder.color); GizmosGL.AddRing(ring.position, ring.up, ring.innerRadius, ring.outerRadius, ring.segments, ring.color); GizmosGL.AddArc(arc.position, arc.up, arc.radius, arc.rotation, arc.halfAngle, arc.segments, arc.color); GizmosGL.AddLine(line.start, line.end, line.startWidth, line.endWidth, line.startColor, line.endColor); for (int i = 0; i < 50; i++) { GizmosGL.AddSphere(new Vector3(Mathf.Sin(i) * 10, i * 10, Mathf.Cos(i) * 10), 1, 16, 16, Color.red); } }
// Calculates force for behaviour public override Vector3 GetForce() { // SET force to zero Vector3 force = Vector3.zero; // IF path is not null AND path Count is greater than zero if (path != null && path.Count > 0) { // SET currentPos to current path[currentNode] position Vector3 currentPos = path[currentNode].position; // IF distance between transform's position and currentPos is less than or equal to nodeRadius if (Vector3.Distance(transform.position, currentPos) <= nodeRadius) { // Increment currentNode currentNode++; // IF currentNode is greater than or equal to path.Count if (currentNode >= path.Count) { // SET currentNode to path.Count - 1 currentNode = path.Count - 1; } } // SET force to Seek() and pass currentPos force = Seek(currentPos); } #region GIZMOS // SET prevposition to path[0].position var prevposition = path[0].position; // FOREACH node in path foreach (var node in path) { // CALL GizmosGL.AddSphere() and pass node's position, graph's nodeRadius, identity, any color GizmosGL.AddSphere(node.position, graph.nodeRadius, transform.rotation, Color.black); // CALL GizmosGL.AddLine() and pass node's position GizmosGL.AddLine(prevposition, node.position); // SET prev to node's position prevposition = node.position; } #endregion // Return force return(force); }
// Move the slected piece if one is selected void MoveSelection() { // chekc if a piece has been selected if (selectedPiece != null) { // Create a new ray from the camera Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GizmosGL.color = Color.yellow; GizmosGL.AddLine(ray.origin, ray.origin + ray.direction * rayDistance, 0.1f, 0.1f); RaycastHit hit; // Raycast to only hit objects that aren't pieces if (Physics.Raycast(ray, out hit, rayDistance, ~selectionIgnoreLayer)) { // Obtain the hit point GizmosGL.color = Color.blue; GizmosGL.AddSphere(hit.point, 0.5f); } } }
public override Vector3 GetForce() { Vector3 force = Vector3.zero; if (target == null) { return(force); } Vector3 desiredForce = transform.position - target.position; if (desiredForce.magnitude > stoppingDistance) { desiredForce = desiredForce.normalized * weight; force = desiredForce - owner.velocity; } GizmosGL.color = Color.yellow; GizmosGL.AddLine(transform.position, transform.position + force, 0.1f, 0.1f); GizmosGL.color = Color.black; GizmosGL.AddLine(transform.position, transform.position + desiredForce, 0.1f, 0.1f); return(force); }
void MoveSelection() { // Check if a piece has been selected if (selectedPiece != null) { // Create a new ray from camera Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GizmosGL.color = Color.yellow; GizmosGL.AddLine(ray.origin, ray.origin + ray.direction * rayDistance); RaycastHit hit; // Raycast to only hit objects that arent piece if (Physics.Raycast(ray, out hit, rayDistance, ~selectionIngoreLayer)) { // Obtain the hit point GizmosGL.color = Color.blue; GizmosGL.AddSphere(hit.point, 0.5f); Vector3 piecePos = hit.point + Vector3.up * pieceHeight; selectedPiece.transform.position = piecePos; } } }
// Calculates force for behaviour public override Vector3 GetForce() { // Set force to zero Vector3 force = Vector3.zero; // If a path is not null AND path count is greater than zero if (path != null && path.Count > 0) { // Set currentPos to path[currentNode] position Vector3 currentPos = path[currentNode].position; // if distance between transfom.position and currentPos is less than or equal to nodeRadius if (Vector3.Distance(transform.position, currentPos) <= nodeRadius) { currentNode++; if (currentNode >= path.Count) { currentNode = path.Count - 1; } } force = Seek(currentPos); #region Gizmos // Set previous position to path[0].position Vector3 previousPos = path[0].position; // Foreach Node in path foreach (Node node in path) { // Call GizmosGl.AddSphere() and pass node.position, graph.nodeRadius, identity, any color GizmosGL.AddSphere(node.position, graph.nodeRadius, Quaternion.identity, Color.blue); // Call GizmosGl.AddLine() and pass previousPos, node.position, 0.1f,0.1f, any color, any color GizmosGL.AddLine(previousPos, node.position, .1f, .1f, Color.red, Color.green); //set previousPos to node.position previousPos = node.position; } #endregion } // RETURN force return(force); }
public override Vector3 GetForce() { Vector3 force = Vector3.zero; if (target == null) { return(force); } Vector3 desiredForce = transform.position - target.position; if (desiredForce.magnitude > stoppingDistance) { desiredForce = desiredForce.normalized * weighting; force = desiredForce - owner.velocity; } #region GizmosGL GizmosGL.color = Color.red; GizmosGL.AddLine(transform.position, transform.position + force, 0.1f); GizmosGL.color = Color.white; GizmosGL.AddLine(transform.position, transform.position + desiredForce, 0.1f); #endregion return(force); }
// Use this for initialization public override Vector3 GetForce() { Vector3 force = Vector3.zero; // we need the max negative and positive float to get most random //HEX 0x7fff = 32767 //this needs to have half of itself taken from itself float randX = Random.RandomRange(0, 0x7fff) - (0x7fff / 2); float randZ = Random.RandomRange(0, 0x7fff) - (0x7fff / 2); /* * -32767 32767 |-----------------------0-----------------------| |_________________________| * random range */ #region Calculate RandomDir //Create a random Direction randomDir = new Vector3(randX, 0f, randZ); //Normalise for the direction randomDir.Normalize(); //aApply jitter to apply magnitude to randomDir randomDir *= jitter; #endregion #region Calculate targetDir //offset the target dir with the random dir targetDir += randomDir; //Normalise the target dir for direction targetDir.Normalize(); //apply the radius as magnitude targetDir *= rad; #endregion //Seek logic Vector3 seekPos = transform.position + targetDir; seekPos += transform.forward * offset; #region GizmosGL GizmosGL.color = Color.red; GizmosGL.AddCircle(seekPos + Vector3.up * .1f, .5f, Quaternion.LookRotation(Vector3.down)); GizmosGL.color = Color.blue; Vector3 offsetPos = transform.position + transform.forward * offset; GizmosGL.AddCircle(offsetPos + Vector3.up * .1f, rad, Quaternion.LookRotation(Vector3.down)); GizmosGL.color = Color.cyan; GizmosGL.AddLine(transform.position, offsetPos, .1f, .1f); #endregion //calculate final force Vector3 direction = seekPos - transform.position; Vector3 desiredForce = Vector3.zero; if (direction != Vector3.zero) { //apply weighting to direction desiredForce = direction.normalized * weight; force = desiredForce - agent.velocity; } return(force); }