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); }
// 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); }
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); } }