Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- #if UNITY_EDITOR
- using UnityEditor;
- #endif
- public class test : MonoBehaviour {
- private Vector3 _directionForward;
- private float _distance_ToTarget_01; private float _distance_ToTarget_02;
- private float _distance_angle_01; private float _distance_angle_02;
- public float _oppositeLength; public float _oppositeAngle;
- public float Check_ObjectIsInPath( Vector3 _position_Start , Vector3 _position_Ahead , Vector3 _position_Target , float _objectRadius){
- _directionForward = _position_Start - _position_Ahead;
- _distance_ToTarget_01 = MyMath.Get_XZ_DistanceAccurate(_position_Start , _position_Target);
- _distance_ToTarget_02 = MyMath.Get_XZ_DistanceAccurate(_position_Ahead , _position_Target);
- if(_distance_ToTarget_01 > _distance_ToTarget_02){
- // facing position ..
- _distance_angle_01 = Vector3.Angle (_position_Start - _position_Target, _directionForward);
- // opposite side length we need == sin of angle01 * length of hyp ..
- _oppositeAngle = Mathf.Sin( _distance_angle_01 * Mathf.Deg2Rad );
- _oppositeLength = _oppositeAngle * _distance_ToTarget_01;
- } else {
- // position behind ..
- _oppositeLength = _objectRadius * 2f; // will clear path regardless ..
- }
- return _oppositeLength; // returns intercept distance from current direction of object. if less than radious will collide ..
- }
- private Vector3 _vect_sp;
- private Vector3 _vect_tp;
- private Vector3 _vect_hit;
- public Transform _car1;
- public Transform _car2;
- private float _distance_start_hit;
- private float _distance_start_tp;
- private float _distance_tp_hit;
- public float _radius = 1f;
- private float _angle;
- #if UNITY_EDITOR
- private Vector3 _tempVect_debug;
- private int _count_debug;
- private Color _debug_Colour01 = Color.cyan;
- private Color _debug_Colour02 = Color.magenta;
- public float _result;
- public float _warningOffset = 0.3f;
- void OnDrawGizmosSelected() {
- if (EditorApplication.isPlaying) {
- if (Global_Vars._Global_GameState._current_gameState == Game_State.GameStates.StartScreen) {
- _vect_sp = _car1.position;
- _vect_tp = _car1.position + (_car1.forward * 0.5f);
- _vect_hit = _car2.position;
- _angle = Check_ObjectIsInPath( _vect_sp , _vect_tp , _vect_hit , _radius );
- _result = (_radius / _angle);
- Gizmos.color = Color.Lerp (Color.white , Color.red , (_result + _warningOffset) );
- Gizmos.DrawWireCube (_car1.position, Vector3.one * (_result + _warningOffset) );
- _vect_tp = _vect_hit + (_car1.right * _oppositeLength);
- Gizmos.DrawLine ( _vect_sp , _vect_tp );
- Gizmos.DrawLine ( _vect_tp , _vect_hit );
- Gizmos.DrawLine ( _vect_sp , _vect_hit );
- }
- }
- }
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement