Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // first need to determine if the character that is moving forward collides with
- // an object in the way
- // the character is moving along 'path', which is a series of waypoints
- dir = transform.forward;
- gizmoBoxHit = Physics.BoxCast(transform.position, new Vector3(1.75f, 1.75f, 0.01f), dir, out boxHit, transform.rotation, 1.75f );
- if ( gizmoBoxHit )
- {
- // here we've correctly determined it hit an object by doing a
- // boxcast forward that is exactly as wide and forward (i think)
- // as the character's collider. I believe its correct because
- // as you can see from the images the character has stopped at the
- // correct point, just in contact with a cylinder based on the
- // boxcast.
- movementPaused = true;
- if (!stopTrying)
- {
- bool foundAround = false; // flag should turn true when way around is found
- float rotateLimit = 180f; // most rotation i want to test
- float rotationInterval = 3f; // increments of rotation tested
- float rotationAdded = 0f; // current cumulative rotation added
- Vector3 currentRotation = transform.rotation.eulerAngles;
- Vector3 facingDirection = transform.forward.normalized;
- float collidedWidth = boxHit.transform.GetComponent<BasicProperties>().colliderRadius * 2f;
- // testLength is how far away I want to point to be in the
- // correct direction, the width of the cylinder plus radius of character
- testLength = basicProperties.colliderRadius + collidedWidth;
- euler = Vector3.zero;
- // loop a cumulative building rotation until you find the
- // correct rotation
- while (!foundAround && rotationAdded < rotateLimit)
- {
- rotationAdded += rotationInterval;
- currentRotation.y += rotationInterval;
- euler = new Vector3(0, rotationAdded, 0);
- LayerMask wtfLayerMask = (1 << LayerMask.NameToLayer("Champions")) | (1 << LayerMask.NameToLayer("NPCs"));
- // HERE LIES THE PROBLEM:
- // BoxCast result should be true until a clear path is found, at which point it should become false. But its becoming false too early,
- // with too small of a rotationAdded
- newPathFoundHit = Physics.BoxCast(transform.position, new Vector3(1.75f, 1.7f, 0.01f), facingDirection, out newPathBoxHit, Quaternion.Euler(euler), testLength, wtfLayerMask);
- if (!newPathFoundHit)
- {
- foundAround = true;
- }
- }
- // based on rotation determined, figure out the point
- Vector3 vector = transform.forward * testLength;
- vector = Quaternion.AngleAxis(rotationAdded, Vector3.up) * vector;
- Vector3 globalVector = transform.TransformPoint(vector);
- // draw a cyan sphere to see where the resulint point is.
- GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
- sphere.GetComponent<Renderer>().material.color = Color.cyan;
- sphere.transform.position = globalVector;
- stopTrying = true;
- }
- }
- else
- {
- movementPaused = false;
- }
Add Comment
Please, Sign In to add comment