Exemple #1
0
		public override void Effect()
		{
			
			Debug.Log ("EFFECT V !!!");

			Ray ray = new Ray();

			RaycastHit rHit;

			ray.origin = hand.transform.position;
			ray.direction = hand.transform.forward;

			Physics.Raycast (ray, out rHit);

			GameObject lightning = (GameObject)MonoBehaviour.Instantiate(lightningObject);
			
			//lightning.transform.position = (hand.transform.position + rHit.transform.position)/2;

			lightning.transform.position = (hand.transform.position + Vector3.forward * 10)/2;

			lightning.transform.position += Vector3.down * 5;

			//Vector3 pathBetween = rHit.transform.position - hand.transform.position;
			Vector3 pathBetween = Vector3.forward * 100;
			
			lightning.transform.eulerAngles = new Vector3(90,180  + Mathf.Rad2Deg * Mathf.Atan( (float)pathBetween.x / pathBetween.z ),180 );
			
			lightning.transform.localScale = pathBetween.magnitude/80 * Vector3.one;

			MonoBehaviour.Destroy ( lightning , 10f);
		}
        protected virtual void Update()
        {
            // Retrieve the frustum planes from the camera.
            frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);

            // Determine if the Tagalong needs to move based on whether its
            // BoxCollider is in or out of the camera's view frustum.
            Vector3 tagalongTargetPosition;
            if (CalculateTagalongTargetPosition(transform.position, out tagalongTargetPosition))
            {
                // Derived classes will use the same Interpolator and may have
                // adjusted its PositionUpdateSpeed for some other purpose.
                // Restore the value we care about and tell the Interpolator
                // to move the Tagalong to its new target position.
                interpolator.PositionPerSecond = PositionUpdateSpeed;
                interpolator.SetTargetPosition(tagalongTargetPosition);
            }
            else if (!interpolator.Running && EnforceDistance)
            {
                // If the Tagalong is inside the camera's view frustum, and it is
                // supposed to stay a fixed distance from the camera, force the
                // tagalong to that location (without using the Interpolator).
                Ray ray = new Ray(Camera.main.transform.position, transform.position - Camera.main.transform.position);
                transform.position = ray.GetPoint(TagalongDistance);
            }
        }
Exemple #3
0
        void Start()
        {
            //	bboxFollower = GetComponent<BoundingBoxFollower>();
            boneFollower = GetComponent<BoneFollower>();

            zeRay = new Ray();
        }
        private IEnumerator CheckAlignment()
        {
            // Continue looping until the game is no longer running.
            while (m_IsGameRunning)
            {
                // If there is a current ring, set it to be unaligned by default.
                if (m_CurrentRing)
                    m_CurrentRing.ShipAligned = false;

                // Create a ray forward from the flyer's current position.
                Ray ray = new Ray (transform.position, Vector3.forward);
                RaycastHit hit;

                // Spherecast along the ray.
                if (Physics.SphereCast (ray, m_Radius, out hit))
                {
                    // Try to find a ring on the hit object.
                    Ring ring = hit.transform.GetComponent<Ring> ();

                    // If it is a ring...
                    if (ring)
                    {
                        // ...  set it as the current ring and the flyer is aligned with it.
                        m_CurrentRing = ring;
                        m_CurrentRing.ShipAligned = true;
                    }
                }

                // Wait until next frame.
                yield return null;
            }
        }
        public override void OnCharacterCollided(ControllerColliderHit hit, Transform other)
        {
            base.OnCharacterCollided(hit, other);

            if (Colliding)
                return;

            //check if hit point beneath player
            var dir = (hit.point - other.position).normalized;
            if (dir.y < -0.9)
                CollisionType = DaggerfallAction.TriggerTypes.WalkOn;
            else
            {
                if (thisAction.TriggerFlag == DaggerfallConnect.DFBlock.RdbTriggerFlags.Collision01)
                {
                    Vector3 origin = new Vector3(hit.controller.transform.position.x, hit.controller.transform.position.y - hit.controller.height / 2, hit.controller.transform.position.z);
                    Ray ray = new Ray(origin, Vector3.down);
                    RaycastHit hitInfo;

                    //if hit not below controller, see if player standing on this action object w/ raycast & if action flag is Collision01 (walk on)
                    //set trigger type & activate if so - to avoid player being able to push against wall to avoid
                    if (hit.collider.Raycast(ray, out hitInfo, hit.controller.skinWidth))
                        CollisionType = DaggerfallAction.TriggerTypes.WalkOn;
                    else
                        CollisionType = DaggerfallAction.TriggerTypes.WalkInto;
                }
                else
                    CollisionType = DaggerfallAction.TriggerTypes.WalkInto;

            }

            Colliding = true;
        }
        void CastRayFromBoundObject()
        {
            hits.Clear();

            //CAST RAY
            Vector3 v = boundObject.position;
            Quaternion q = boundObject.rotation;
            ray = new Ray(v, q * Vector3.forward);
            hits.AddRange(Physics.RaycastAll(ray, interactDistance));
            eventData.previousRaycast = eventData.currentRaycast;

            if (hits.Count == 0) {
                eventData.currentRaycast = null;
                return;
            }

            //FIND THE CLOSEST OBJECT
            RaycastHit minHit = hits[0];
            for (int i = 0; i < hits.Count; i++) {
                if (hits[i].distance < minHit.distance) {
                    minHit = hits[i];
                }
            }

            //MAKE SURE CLOSEST OBJECT IS INTERACTABLE
            if (interactTag != null && interactTag.Length > 1 && !minHit.transform.tag.Equals(interactTag)) {
                eventData.currentRaycast = null;
                return;
            } else {
                eventData.currentRaycast = minHit.transform.gameObject;
            }
        }
        private void DropToNearestFloor(bool withBlink)
        {
            if (enableTeleport && eyeCamera.transform.position.y > this.transform.position.y)
            {
                //send a ray down to find the closest object to stand on
                Ray ray = new Ray(eyeCamera.transform.position, -transform.up);
                RaycastHit rayCollidedWith;
                bool rayHit = Physics.Raycast(ray, out rayCollidedWith);
                float floorY = eyeCamera.transform.position.y - rayCollidedWith.distance;

                if (rayHit && ValidLocation(rayCollidedWith.transform) && !FloorIsGrabbedObject(rayCollidedWith) && (MeshYChanged(rayCollidedWith, floorY) || CurrentFloorChanged(rayCollidedWith)))
                {
                    currentFloor = rayCollidedWith.transform.gameObject;
                    currentRayDownY = floorY;

                    if (withBlink && !rayCollidedWith.transform.GetComponent<MeshCollider>())
                    {
                        Blink(blinkTransitionSpeed);
                    }

                    Vector3 newPosition = new Vector3(this.transform.position.x, floorY, this.transform.position.z);
                    var teleportArgs = new DestinationMarkerEventArgs
                    {
                        destinationPosition = newPosition,
                        distance = rayCollidedWith.distance,
                        enableTeleport = true,
                        target = currentFloor.transform
                    };
                    OnTeleporting(gameObject, teleportArgs);
                    SetNewPosition(newPosition, currentFloor.transform);
                    OnTeleported(gameObject, teleportArgs);
                }
            }
        }
        void Update()
        {
            _ray = new Ray(transform.position, transform.forward);
            if (Physics.Raycast(_ray, out _hit, interactionRange))
            {
                Interactable i = _hit.transform.GetComponent<Interactable>();
                if (i)
                {
                    if (_interactableObject != null && !i.Equals(_interactableObject))
                    {
                        _interactableObject.interacting = false;
                        this.interacting = false;
                    }

                    _interactableObject = _hit.transform.GetComponent<Interactable>();
                    this.interacting = true;
                    _interactableObject.interacting = true;
                    _interactableObject.interactPosition = _hit.point;
                }
            }
            else if (_interactableObject)
            {
                _interactableObject.interacting = false;
                this.interacting = false;
                _interactableObject = null;
            }
        }
 void Update() {
   Vector3 forward = RaycastSource.TransformDirection(Vector3.forward);
   bool didHit = Physics.Raycast(RaycastSource.position, forward, out hit, MaxDistance, Collidable);
   if (ObjectToPosition != null) {
     if (didHit) {
       ObjectToPosition.transform.position = hit.point;
       lastLegalPlane.SetNormalAndPosition(Vector3.up, 
                                           new Vector3(0, ObjectToPosition.transform.position.y, 0));
     } else {
       Ray castRay = new Ray(RaycastSource.transform.position, RaycastSource.transform.forward);
       float rayDistance;
       if (lastLegalPlane.Raycast(castRay, out rayDistance)) {
         ObjectToPosition.transform.position = castRay.GetPoint(rayDistance);
       }
     }
   }
   if (UseLineRenderer) {
     if (didHit) {
       if (Line.gameObject.activeSelf == false) {
         Line.gameObject.SetActive(true);
       }
       Line.SetPosition(0, RaycastSource.transform.position);
       Line.SetPosition(1, ObjectToPosition.transform.position);
     } else if (Line.gameObject.activeSelf == true)
       Line.gameObject.SetActive(false);
   }
 }
        private float GetHitDistance(Ray ray)
        {
            var hitDistance = float.MaxValue;

            if (canvas.renderMode != RenderMode.ScreenSpaceOverlay && blockingObjects != BlockingObjects.None)
            {
                var maxDistance = Vector3.Distance(ray.origin, canvas.transform.position);

                if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
                {
                    RaycastHit hit;
                    Physics.Raycast(ray, out hit, maxDistance);
                    if (hit.collider && !hit.collider.GetComponent<VRTK_PlayerObject>())
                    {
                        hitDistance = hit.distance;
                    }
                }

                if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
                {
                    RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, maxDistance);

                    if (hit.collider != null && !hit.collider.GetComponent<VRTK_PlayerObject>())
                    {
                        hitDistance = hit.fraction * maxDistance;
                    }
                }
            }
            return hitDistance;
        }
		void Update ()
		{
		
			if (Showtime) {
				if (Time.time >= timeTemp + Delay) {
				
					Ray ray = new Ray (this.transform.position + new Vector3 (Random.Range (-RandomSize, RandomSize), 0, Random.Range (-RandomSize, RandomSize)), -Vector3.up);
					RaycastHit hit;
					if (Physics.Raycast (ray, out hit, 100))
						positionLook = hit.point;

				
					Quaternion look = Quaternion.LookRotation ((positionLook - this.transform.position).normalized);
					look.eulerAngles = new Vector3 (0, look.eulerAngles.y, 0);
					this.transform.rotation = look;
					if (RandomSkill) {
						Index = Random.Range (0, Skills.Length);
					} else {
						Index += 1;
					}
					Deploy ();
					timeTemp = Time.time;	
				}
			} else {
				Aim ();
				if (Input.GetMouseButtonDown(0)) {
					Deploy ();
				}
			}
			KeyUpdate();
		}
        void OnMouseOver() // event souris dessus
        {
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Physics.Raycast(ray, out hit, 100);
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                if (!hit.Equals(null))
                {
                    if (hit.collider == myCollider) // Collision clic
                    {
                        // myMenu.update_Color(myColor); 
                        // Change la couleur des valeurs -> est maintenant directement géré depuis le updateValuesPlayer du playerController

                        GetComponent<Transform>().parent.parent.gameObject.GetComponent<BasicPlayerController>().updateValuesPlayer(myColor);
                        /*
						if (PhotonNetwork.inRoom) {
							GetComponent<Transform> ().parent.parent.gameObject.GetComponent<PlayerController> ().updateValuesPlayer (myColor);
						} else {
							GetComponent<Transform>().parent.parent.gameObject.GetComponent<Player_controller>().updateValuesPlayer(myColor);
						}*/
                        transform.localScale -= new Vector3(0.02f, 0.02f, 0.02f);
                    }
                }
            }
            if (Input.GetKeyUp(KeyCode.Mouse0))
            {
                transform.localScale += new Vector3(0.02f, 0.02f, 0.02f);
            }
        }
Exemple #13
0
        public override void OnStart()
        {
            RaycastHit hit;
            int raycastCount = 0;
            var direction = transform.forward;
            float step = 0;
            // Keep firing a ray until too many rays have been fired
            while (raycastCount < maxRaycasts.Value) {
                var ray = new Ray(transform.position, direction);
                if (Physics.Raycast(ray, out hit, maxCoverDistance.Value, availableLayerCovers.value)) {
                    // A suitable agent has been found. Find the opposite side of that agent by shooting a ray in the opposite direction from a point far away
                    if (hit.collider.Raycast(new Ray(hit.point - hit.normal * maxCoverDistance.Value, hit.normal), out hit, Mathf.Infinity)) {
                        coverPoint = hit.point;
                        break;
                    }
                }
                // Keep sweeiping along the y axis
                step += rayStep.Value;
                direction = Quaternion.Euler(0, 0, transform.eulerAngles.z + step) * Vector3.up;
                raycastCount++;
            }

            SetDestination(Target());

            base.OnStart();
        }
Exemple #14
0
		public static bool RaycastSmoke(Ray ray)
		{
			if(!CMDropper.smokePool)
			{
				return false;
			}

			for(int i = 0; i < CMDropper.smokePool.size; i++)
			{
				Transform smokeTf = CMDropper.smokePool.GetPooledObject(i).transform;
				if(smokeTf.gameObject.activeInHierarchy)
				{
					Plane smokePlane = new Plane((ray.origin-smokeTf.position).normalized, smokeTf.position);
					float enter;
					if(smokePlane.Raycast(ray, out enter))
					{
						float dist = (ray.GetPoint(enter)-smokeTf.position).magnitude;
						if(dist < 16)
						{
							return true;
						}
					}
				}
			}

			return false;
		}
        private void Update()
        {
            InteractionText.text = "";

            RaycastHit hit;
            var cam = UnityEngine.Camera.main.transform;
            var forward = cam.forward;
            var position = cam.position;

            var ray = new Ray(position, forward);

            if (Physics.Raycast(ray, out hit))
            {
                var interaction = hit.collider.GetComponent<IInteractable>();
                if (interaction != null && Vector3.Distance(transform.position, hit.collider.transform.position) < InteractionDistance)
                {
                    if (Input.GetKeyDown(KeyCode.E))
                    {
                        interaction.Interact();
                    }
                    else
                    {
                        InteractionText.text = "Press E to interact";
                    }
                }
            }
        }
Exemple #16
0
        // Update is called once per frame
        public override void OnUpdate()
        {
            var vrcam = SteamVR_Render.Top();
            GameObject go = Fsm.GetOwnerDefaultTarget(gazeObject);

                Ray r = new Ray(vrcam.transform.position, vrcam.transform.forward);
                Plane p = new Plane(vrcam.transform.forward, go.transform.position);

                float enter = 0.0f;
                if (p.Raycast(r, out enter))
                {
                    Vector3 intersect = vrcam.transform.position + vrcam.transform.forward * enter;
                    float dist = Vector3.Distance(intersect, go.transform.position);
                    //Debug.Log("Gaze dist = " + dist);
                    if (dist < gazeInCutoff.Value && !isInGaze.Value)
                    {
                        isInGaze.Value = true;
                        GazeEventArgsPlaymaker e;
                        e.distance = dist;
                        OnGazeOn(e);
                    }
                    else if (dist >= gazeOutCutoff.Value && isInGaze.Value)
                    {
                        isInGaze.Value = false;
                        GazeEventArgsPlaymaker e;
                        e.distance = dist;
                        OnGazeOff(e);
                    }

                }
        }
Exemple #17
0
        public static Vector2 ClosestPointToRay(Ray ray, Vector2 point)
        {
            //http://pastie.org/1066490
            var t = Vector2.Dot(point - (Vector2) ray.origin, ray.direction);

            return ray.GetPoint(t);
        }
        /// <summary>
        /// Updates the StableHeadPosition and StableHeadRotation based on GazeSample values.
        /// Call this method with Raycasthit parameters to get stable values.
        /// </summary>
        /// <param name="position">Position value from a RaycastHit point.</param>
        /// <param name="rotation">Rotation value from a RaycastHit rotation.</param>
        public void UpdateHeadStability(Vector3 position, Quaternion rotation)
        {
            Vector3 gazePosition = position;
            Vector3 gazeDirection = rotation * Vector3.forward;

            positionRollingStats.AddSample(gazePosition);
            directionRollingStats.AddSample(gazeDirection);

            float lerpPower = unstabalizedLerpFactor;
            if (positionRollingStats.ActualSampleCount > minimumSamplesRequiredToStabalize && // we have enough samples and...
                (positionRollingStats.CurrentStandardDeviation > positionStandardDeviationReset || // the standard deviation of positions is high or...
                 directionRollingStats.CurrentStandardDeviation > directionStandardDeviationReset)) // the standard deviation of directions is high
            { 
                // We've detected that the user's gaze is no longer fixed, so stop stabalizing so that gaze is responsive.
                //Debug.LogFormat("Reset {0} {1} {2} {3}", positionRollingStats.standardDeviation, positionRollingStats.standardDeviationsAway, directionRollignStats.standardDeviation, directionRollignStats.standardDeviationsAway);
                positionRollingStats.Reset();
                directionRollingStats.Reset();
            }
            else if (positionRollingStats.ActualSampleCount > minimumSamplesRequiredToStabalize)
            {
                // We've detected that the user's gaze is fairly fixed, so start stabalizing.  The more fixed the gaze the less the cursor will move.
                lerpPower = stabalizedLerpBoost * (positionRollingStats.CurrentStandardDeviation + directionRollingStats.CurrentStandardDeviation);
            }

            StableHeadPosition = Vector3.Lerp(StableHeadPosition, gazePosition, lerpPower);
            StableHeadRotation = Quaternion.LookRotation(Vector3.Lerp(StableHeadRotation * Vector3.forward, gazeDirection, lerpPower));
            StableHeadRay = new Ray(StableHeadPosition, StableHeadRotation * Vector3.forward);
        }
 private void UpdatePointer() {
   bool handled = true;
   pointerRay = new Ray(transform.position, transform.forward);
   if (InteractedObject != null) {
     ExecuteEvents.ExecuteHierarchy<IRemoteInputEventHandler>(InteractedObject, null,
         (x, y) => x.OnRemoteOrientation(out handled, transform));
     LaserPointer.PointerTarget = TargetedObject.transform.position;
     if (!handled) {
       InteractedObject = null;
     }
   } else if (Physics.Raycast(pointerRay, out pointerHit, PointerDistance)) {
     if (ExecuteEvents.ExecuteHierarchy<IRemoteInputEventHandler>(pointerHit.collider.gameObject, null,
         (x, y) => x.OnRemotePointEnter(out handled))) {
       if (TargetedObject != null && !TargetedObject.Equals(pointerHit.collider.gameObject)) {
         ExecuteEvents.Execute<IRemoteInputEventHandler>(TargetedObject, null,
             (x, y) => x.OnRemotePointExit(out handled));
       }
       TargetedObject = pointerHit.collider.gameObject;
     } else if (TargetedObject != null) {
       ExecuteEvents.ExecuteHierarchy<IRemoteInputEventHandler>(TargetedObject, null,
           (x, y) => x.OnRemotePointExit(out handled));
       TargetedObject = null;
     }
     LaserPointer.PointerTarget = pointerHit.point;
   } else {
     LaserPointer.PointerTarget = transform.position + transform.forward * PointerDistance;
     if (TargetedObject != null) {
       ExecuteEvents.ExecuteHierarchy<IRemoteInputEventHandler>(TargetedObject, null,
           (x, y) => x.OnRemotePointExit(out handled));
       TargetedObject = null;
     }
   }
 }
Exemple #20
0
		public IEnumerator FollowMouse(GameObject _item)
		{
			Debug.Log("follow mouse started");
			while (Input.GetMouseButton(0) == true)
			{
				float _mouseXR = (Mathf.Round(Input.mousePosition.x * 2)) / 2;
				float _mouseYR = (Mathf.Round(Input.mousePosition.y * 2)) / 2;
				Vector3 _mouseVR = new Vector3(_mouseXR, _mouseYR , 0.0f);
				_item.transform.position = _mouseVR * Time.deltaTime;
			}
			Debug.Log ("Leaving loop");
			Debug.Log ("checking underneath");
			RaycastHit _rayHit;
			Ray _ray = new Ray( _item.transform.position, Vector3.down);
			Debug.Log("did i hit?");
			if (Physics.Raycast(_ray, out _rayHit))
			{
				if (_rayHit.collider.gameObject.tag == "floor")
				{
					_item.transform.position = _rayHit.collider.gameObject.transform.position;
					Debug.Log("yes");
				}
			}
			else 
			{
				Debug.Log ("no");
				DestroyObject(_item);
			}
			yield return null;

		}
        //Calculate the bounce and turn the ball into that direction.
        private void Update()
        {
            Ray ray = new Ray(transform.position, transform.forward);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, Time.deltaTime * LS_moveSpeed + 0.1f, LS_LayerMask))
            {
                //Show the normal of the plane
                Debug.DrawRay(transform.position, transform.forward);

                //Reflect the electricity
                Vector3 reflectDir = Vector3.Reflect(ray.direction, hit.normal);

                //Calculate the turn of the electricity
                float rot = 90 - Mathf.Atan2(reflectDir.z, reflectDir.x) * Mathf.Rad2Deg;
                transform.eulerAngles = new Vector3(0, rot, 0);

                //Add some moveSpeed
                LS_moveSpeed += 0.5f;
            }

            //Move the player and set the movespeed.
            transform.Translate(Vector3.forward * Time.deltaTime * LS_moveSpeed);
            LS_moveSpeed = Mathf.Clamp(LS_moveSpeed, 3, LS_maxSpeed);
        }
        void FixedUpdate()
        {
            float fmotion = -InputManager.Instance.GetAxis("DEDH_FMotion" + _PlayerID);
            float smotion = InputManager.Instance.GetAxis("DEDH_RMotion" + _PlayerID);

            _RBody.drag = _Drag;
            _RBody.angularDrag = _ADrag;

            _RTorque = _RTorque - (_RBody.velocity.magnitude / 300);
            _RTorque += 1;
            _RTorque = Mathf.Clamp(_RTorque, 1, 5);

            _RBody.AddForce(fmotion * (_MForce - 40 - _RBody.velocity.magnitude) * transform.forward);
            _RBody.AddTorque(smotion * _RTorque * Vector3.up);

            RaycastHit hit;
            Ray dray = new Ray(transform.position, -Vector3.up);

            if (Physics.Raycast(dray, out hit))
            {
                if (hit.transform.tag == "Tag 4")
                {
                    float hoverError = _HHeight - hit.distance;
                    if (hoverError > 0)
                    {
                        float upwardSpeed = _RBody.velocity.y;
                        float lift = hoverError * _HForce - upwardSpeed * _HDamp;
                        _RBody.AddForce(lift * new Vector3(0, 90, 0));
                    }
                }
            }
        }
        public override MovementOutput GetMovement()
        {
            RaycastHit rayVector = new RaycastHit();
            Collider hitbox = AvoidObstacle.GetComponent<Collider>();

            Ray centralRay = new Ray(this.Character.position, this.Character.velocity.normalized);
            bool collision = hitbox.Raycast(centralRay, out rayVector, lookAhead);
            if (collision)
            {
                Target.position = rayVector.point + rayVector.normal * avoidDistance;
                return base.GetMovement();
            }

            Ray whiskerRay1 = new Ray(this.Character.position, Util.MathHelper.Rotate2D(Character.velocity.normalized, ((float)System.Math.PI) / 4.0f).normalized);
            collision = hitbox.Raycast(whiskerRay1, out rayVector, whiskersLookAhead);
            if (collision)
            {
                Target.position = rayVector.point + rayVector.normal * avoidDistance;
                return base.GetMovement();
            }
            Ray whiskerRay2 = new Ray(this.Character.position, Util.MathHelper.Rotate2D(Character.velocity.normalized, -((float)System.Math.PI) / 4.0f).normalized);
            collision = hitbox.Raycast(whiskerRay2, out rayVector, whiskersLookAhead);
            if (collision)
            {
                Target.position = rayVector.point + rayVector.normal * avoidDistance;
                return base.GetMovement();
            }

            return new MovementOutput();
        }
Exemple #24
0
 static int Raycast(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         UnityEngine.Collider   obj  = (UnityEngine.Collider)ToLua.CheckObject <UnityEngine.Collider>(L, 1);
         UnityEngine.Ray        arg0 = ToLua.ToRay(L, 2);
         UnityEngine.RaycastHit arg1;
         float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
         bool  o    = obj.Raycast(arg0, out arg1, arg2);
         LuaDLL.lua_pushboolean(L, o);
         if (o)
         {
             ToLua.Push(L, arg1);
         }
         else
         {
             LuaDLL.lua_pushnil(L);
         }
         return(2);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
        protected override bool CheckCanRotate()
        {
            float rayDistance = 1.0f;

            Ray ray0 = new Ray();

            ray0.origin = Cube0.transform.position;

            switch (mPositionIndex)
            {
                case 0:
                    ray0.direction = Vector3.down;
                    break;
                case 1:
                    ray0.direction = Vector3.left;
                    break;
                case 2:
                    ray0.direction = Vector3.up;
                    break;
                case 3:
                    ray0.direction = Vector3.right;
                    break;
                default:
                    Debug.LogError("Wrong mPositionIndex");
                    break;
            }
            bool trigegr0 = CheckRaycastHit(ray0, rayDistance);

            if (trigegr0 == true)
            {
                return false;
            }

            return true;
        }
Exemple #26
0
        private const float k_PowerUpWaitTime = 2.033f;             // The amount of time it takes for the turret to power up (based on the animation).


        private void AimAtPlayer()
        {
            // Find the players position but at the rotators height.
            Vector3 playerAtTurretHeight = m_PlayerTransform.position;
            playerAtTurretHeight.y = m_TurretRotator.position.y;

            // Find a rotation of the turret rotating to facing the player.
            Quaternion newRotation = Quaternion.LookRotation(playerAtTurretHeight - m_TurretRotator.position);

            // If the normalised time hasn't reached 1 yet, increment it.
            if (m_AimTimer < 1f)
                m_AimTimer += Time.deltaTime / m_AimTime;
            else
                m_AimTimer = 1f;

            // Use the normalised time to rotate the turret smoothly so that it's facing the player.
            m_TurretRotator.rotation = Quaternion.Slerp(m_TurretRotator.rotation, newRotation, m_AimTimer);
            
            // Create a ray from the turret in the direction of the turret to the player.
            Ray ray = new Ray(m_TurretRotator.position, playerAtTurretHeight - m_TurretRotator.position);
            RaycastHit hit;

            // The player is in sight if the raycast hits something and the transform of what's been hit is the player's transform.
            m_PlayerInSight = Physics.Raycast(ray, out hit, m_Range) && hit.transform == m_PlayerTransform;

            // However the player only counts as being in sight if it's not dead.
            m_PlayerInSight &= !m_Player.Dead;
        }
 	public static bool IntersectRayMesh(Ray ray, Mesh mesh, Matrix4x4 matrix, out RaycastHit hit)
 	{
 		var parameters = new object[]{ray,mesh,matrix,null};
 		bool result = (bool)meth_IntersectRayMesh.Invoke(null,parameters);
 		hit = (RaycastHit)parameters[3];
       return result;
    }
        public override void Start()
        {
            currentTime = 0.0f;
            Enemy enemy = components.action_target.GetComponent<Enemy>();
            Collider2D[] hazards = Physics2D.OverlapCircleAll(enemy.transform.position, fieldOfReaction, 4096);

            for (int i = 0; i < hazards.Length; i++)
            {
                Vector3 hazardPosition = hazards[i].transform.position;
                Vector3 delta = hazardPosition - enemy.transform.position;

                Vector3 optionA = Vector3.Cross(Vector3.forward, delta); optionA = optionA.normalized;
                Vector3 optionB = Vector3.Reflect(optionA, delta); optionB = optionB.normalized;
                Vector3 optionC = delta * -1; optionC = optionC.normalized;

                Vector2[] options = new Vector2[] { optionA, optionB, optionC };

                for (int c = 0; c < options.Length; c++)
                {
                    Ray ray = new Ray(enemy.transform.position, options[c].normalized);
                    RaycastHit2D hit = Physics2D.GetRayIntersection(ray, speed, 256);
                    if (hit)
                    {
                        if (hit.distance < speed * 0.8f) continue;

                        enemy.Impulse(options[c].normalized, speed);
                    }
                    else
                    {
                        enemy.Impulse(options[c].normalized, speed);
                    }
                }
            }
        }
        public KinematicData willViolate()
        {
            RaycastHit rayVector = new RaycastHit();
            foreach (var bot in this.bots) {

                Collider hitbox = bot.GetComponent<Collider>();

                Vector3 tempVect = this.character.KinematicData.velocity.normalized;

                if (this.character.KinematicData.velocity.magnitude != 0.0f && tempVect.magnitude != 0.0f)
                {
                    Ray centralRay = new Ray(this.character.KinematicData.position, this.character.KinematicData.velocity.normalized);

                    if (hitbox.Raycast(centralRay, out rayVector, 15.0f))
                    {
                        this.pedestrian = new DynamicCharacter(bot)
                        {
                            Drag = 15.0f,
                            MaxSpeed = 20.0f

                        };

                        return this.pedestrian.KinematicData;
                    }
                }
            }

            return null;
        }
Exemple #30
0
        IEnumerator FireLaser()
        {
            _line.enabled = true;
            _light.enabled = true;

            while (Input.GetButton("Fire1"))
            {
                _renderer.material.mainTextureOffset = new Vector2(Time.time, Time.time);

                Ray ray = new Ray(transform.position, transform.forward);
                RaycastHit hit;

                _line.SetPosition(0, ray.origin);

                if (Physics.Raycast(ray, out hit, 100))
                {
                    _line.SetPosition(1, hit.point);
                    EBunny_Status status = hit.collider.GetComponent<EBunny_Status>();
                    if (status)
                    {
                        status.ApplyDamage(LaserDamage);
                    }
                }
                else
                    _line.SetPosition(1, ray.GetPoint(100));

                yield return null;
            }

            _line.enabled = false;
            _light.enabled = false;
        }
        // Spherecast from the root to find ground height
        protected virtual RaycastHit GetSpherecastHit()
        {
            Ray ray = new Ray (r.position + Vector3.up * airborneThreshold, Vector3.down);
            RaycastHit h = new RaycastHit();

            Physics.SphereCast(ray, spherecastRadius, out h, airborneThreshold * 2f, groundLayers);
            return h;
        }
Exemple #32
0
 static public int ctor_s(IntPtr l)
 {
     try {
         UnityEngine.Ray o;
         o = new UnityEngine.Ray();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int ScreenPointToRay(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.Camera  arg0 = (UnityEngine.Camera)ToLua.CheckObject(L, 1, typeof(UnityEngine.Camera));
         UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 2);
         UnityEngine.Ray     o    = UnityEngine.RectTransformUtility.ScreenPointToRay(arg0, arg1);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.Ray     o;
         UnityEngine.Vector3 a1;
         checkType(l, 2, out a1);
         UnityEngine.Vector3 a2;
         checkType(l, 3, out a2);
         o = new UnityEngine.Ray(a1, a2);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    static bool InterSectWithAABB(UnityEngine.Ray ray, Aabb aabb)
    {
        double tx1 = (aabb.Min.x - ray.origin.x) * (1 / ray.direction.x);
        double tx2 = (aabb.Max.x - ray.origin.x) * (1 / ray.direction.x);

        double tmin = math.min(tx1, tx2);
        double tmax = math.max(tx1, tx2);

        double ty1 = (aabb.Min.y - ray.origin.y) * (1 / ray.direction.y);
        double ty2 = (aabb.Max.y - ray.origin.y) * (1 / ray.direction.y);

        tmin = math.max(tmin, math.min(ty1, ty2));
        tmax = math.min(tmax, math.max(ty1, ty2));

        double tz1 = (aabb.Min.z - ray.origin.z) * (1 / ray.direction.z);
        double tz2 = (aabb.Max.z - ray.origin.z) * (1 / ray.direction.z);

        tmin = math.max(tmin, math.min(tz1, tz2));
        tmax = math.min(tmax, math.max(tz1, tz2));

        UnityEngine.Debug.LogFormat("tmin : {0} tmax : {1}", tmin, tmax);
        return(tmax >= tmin);
    }
Exemple #36
0
 public bool SphereCast(UnityEngine.Ray ray, float radius, out UnityEngine.RaycastHit hitInfo)
 {
     return(Physics.SphereCast(ray, radius, out hitInfo));
 }
Exemple #37
0
 public bool SphereCast(UnityEngine.Ray ray, float radius, out UnityEngine.RaycastHit hitInfo, float distance, int layerMask)
 {
     return(Physics.SphereCast(ray, radius, out hitInfo, distance, layerMask));
 }
Exemple #38
0
 public UnityEngine.RaycastHit[] SphereCastAll(UnityEngine.Ray ray, float radius)
 {
     return(Physics.SphereCastAll(ray, radius));
 }
Exemple #39
0
 public UnityEngine.RaycastHit[] SphereCastAll(UnityEngine.Ray ray, float radius, float distance, int layerMask)
 {
     return(Physics.SphereCastAll(ray, radius, distance, layerMask));
 }
 /// <summary>Calcule la distance signée entre une droite et un plan. Le signe dépend du côté duquel se trouve la droite par rapport au plan. Vaut 0 si ils ne sont pas parallèles.</summary>
 public static float DistSigned(Line l, Plane p)
 {
     return(DistSigned(p, l));
 }
 /// <summary>Calcule la plus petite distance entre la droite et le point</summary>
 public static float Dist(Line l, Point p)
 {
     return(Point.Cross((p - l.origin), l.direction).magnitude / l.direction.magnitude);
 }
Exemple #42
0
    static int SphereCastAll(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray), typeof(float)))
            {
                UnityEngine.Ray          arg0 = ToLua.ToRay(L, 1);
                float                    arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.RaycastHit[] o    = UnityEngine.Physics.SphereCastAll(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray), typeof(float), typeof(float)))
            {
                UnityEngine.Ray          arg0 = ToLua.ToRay(L, 1);
                float                    arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                float                    arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                UnityEngine.RaycastHit[] o    = UnityEngine.Physics.SphereCastAll(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(float), typeof(UnityEngine.Vector3)))
            {
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 1);
                float arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.Vector3      arg2 = ToLua.ToVector3(L, 3);
                UnityEngine.RaycastHit[] o    = UnityEngine.Physics.SphereCastAll(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(float), typeof(UnityEngine.Vector3), typeof(float)))
            {
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 1);
                float arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.Vector3 arg2 = ToLua.ToVector3(L, 3);
                float arg3 = (float)LuaDLL.lua_tonumber(L, 4);
                UnityEngine.RaycastHit[] o = UnityEngine.Physics.SphereCastAll(arg0, arg1, arg2, arg3);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray), typeof(float), typeof(float), typeof(int)))
            {
                UnityEngine.Ray          arg0 = ToLua.ToRay(L, 1);
                float                    arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                float                    arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                int                      arg3 = (int)LuaDLL.lua_tonumber(L, 4);
                UnityEngine.RaycastHit[] o    = UnityEngine.Physics.SphereCastAll(arg0, arg1, arg2, arg3);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(float), typeof(UnityEngine.Vector3), typeof(float), typeof(int)))
            {
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 1);
                float arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                UnityEngine.Vector3 arg2 = ToLua.ToVector3(L, 3);
                float arg3 = (float)LuaDLL.lua_tonumber(L, 4);
                int   arg4 = (int)LuaDLL.lua_tonumber(L, 5);
                UnityEngine.RaycastHit[] o = UnityEngine.Physics.SphereCastAll(arg0, arg1, arg2, arg3, arg4);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Physics.SphereCastAll"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemple #43
0
 public UnityEngine.RaycastHit[] RaycastAll(UnityEngine.Ray ray, float distance)
 {
     return(Physics.RaycastAll(ray, distance));
 }
Exemple #44
0
 public UnityEngine.RaycastHit[] RaycastAll(UnityEngine.Ray ray)
 {
     return(Physics.RaycastAll(ray));
 }
Exemple #45
0
 public bool SphereCast(UnityEngine.Ray ray, float radius)
 {
     return(Physics.SphereCast(ray, radius));
 }
Exemple #46
0
        public static void ReportOnPointerUpEvent(ACTION_BUTTON buttonId, string sceneId, string uuid, string entityId, string meshName, Ray ray, Vector3 point, Vector3 normal, float distance)
        {
            if (string.IsNullOrEmpty(uuid))
            {
                return;
            }

            onPointerUpEvent.uuid = uuid;
            SetPointerEventPayload(onPointerEventPayload, buttonId, entityId, meshName, ray, point, normal, distance, isHitInfoValid: true);
            onPointerUpEvent.payload = onPointerEventPayload;

            SendSceneEvent(sceneId, "uuidEvent", onPointerUpEvent);
        }
 /// <summary>Calcule la distance entre une droite et une sphère. Peut être négatif : entre 0 si la droite est tangeante à la surface de la sphère, et -rayon si la droite traverse le centre de la sphère.</summary>
 public static float Dist(Sphere s, Line l)
 {
     return(Dist(s.position, l) - s.radius);
 }
 /// <summary>Calcule la distance entre une droite et une sphère. Si c'est négatif, indique la profondeur de la droite dans la sphère.</summary>
 public static float Dist(Line l, SphereCollider s)
 {
     return(Dist(s, l));
 }
 /// <summary>Calcule la distance entre une droite et une sphère. Si c'est négatif, indique la profondeur de la droite dans la sphère.</summary>
 public static float Dist(SphereCollider s, Line l)
 {
     return(Dist(ToSphere(s), l));
 }
 /// <summary>Calcule la plus petite distance entre la droite et le point</summary>
 public static float Dist(Point p, Line l)
 {
     return(Dist(l, p));
 }
Exemple #51
0
 public UnityEngine.RaycastHit[] RaycastAll(UnityEngine.Ray ray, float distance, int layerMask)
 {
     return(Physics.RaycastAll(ray, distance, layerMask));
 }
Exemple #52
0
        private static void SetPointerEventPayload(OnPointerEventPayload pointerEventPayload, ACTION_BUTTON buttonId, string entityId, string meshName, Ray ray, Vector3 point, Vector3 normal, float distance, bool isHitInfoValid)
        {
            pointerEventPayload.origin    = ray.origin;
            pointerEventPayload.direction = ray.direction;
            pointerEventPayload.buttonId  = buttonId;

            if (isHitInfoValid)
            {
                pointerEventPayload.hit = CreateHitObject(entityId, meshName, point, normal, distance);
            }
            else
            {
                pointerEventPayload.hit = null;
            }
        }
Exemple #53
0
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.Ray ray = (UnityEngine.Ray)value;
     writer.WriteProperty("origin", ray.origin);
     writer.WriteProperty("direction", ray.direction);
 }
Exemple #54
0
 public List <SVONode> Trace(UnityEngine.Ray ray)
 {
     return(tracer.Trace(ray, svo));
 }
Exemple #55
0
    static int Raycast(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray)))
            {
                UnityEngine.Ray arg0 = ToLua.ToRay(L, 1);
                bool            o    = UnityEngine.Physics.Raycast(arg0);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray), typeof(float)))
            {
                UnityEngine.Ray arg0 = ToLua.ToRay(L, 1);
                float           arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                bool            o    = UnityEngine.Physics.Raycast(arg0, arg1);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray), typeof(LuaInterface.LuaOut <UnityEngine.RaycastHit>)))
            {
                UnityEngine.Ray        arg0 = ToLua.ToRay(L, 1);
                UnityEngine.RaycastHit arg1;
                bool o = UnityEngine.Physics.Raycast(arg0, out arg1);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.Push(L, arg1);
                return(2);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3)))
            {
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 1);
                UnityEngine.Vector3 arg1 = ToLua.ToVector3(L, 2);
                bool o = UnityEngine.Physics.Raycast(arg0, arg1);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray), typeof(float), typeof(int)))
            {
                UnityEngine.Ray arg0 = ToLua.ToRay(L, 1);
                float           arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                int             arg2 = (int)LuaDLL.lua_tonumber(L, 3);
                bool            o    = UnityEngine.Physics.Raycast(arg0, arg1, arg2);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3), typeof(float)))
            {
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 1);
                UnityEngine.Vector3 arg1 = ToLua.ToVector3(L, 2);
                float arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                bool  o    = UnityEngine.Physics.Raycast(arg0, arg1, arg2);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray), typeof(LuaInterface.LuaOut <UnityEngine.RaycastHit>), typeof(float)))
            {
                UnityEngine.Ray        arg0 = ToLua.ToRay(L, 1);
                UnityEngine.RaycastHit arg1;
                float arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                bool  o    = UnityEngine.Physics.Raycast(arg0, out arg1, arg2);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.Push(L, arg1);
                return(2);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3), typeof(LuaInterface.LuaOut <UnityEngine.RaycastHit>)))
            {
                UnityEngine.Vector3    arg0 = ToLua.ToVector3(L, 1);
                UnityEngine.Vector3    arg1 = ToLua.ToVector3(L, 2);
                UnityEngine.RaycastHit arg2;
                bool o = UnityEngine.Physics.Raycast(arg0, arg1, out arg2);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.Push(L, arg2);
                return(2);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3), typeof(float), typeof(int)))
            {
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 1);
                UnityEngine.Vector3 arg1 = ToLua.ToVector3(L, 2);
                float arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                int   arg3 = (int)LuaDLL.lua_tonumber(L, 4);
                bool  o    = UnityEngine.Physics.Raycast(arg0, arg1, arg2, arg3);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3), typeof(LuaInterface.LuaOut <UnityEngine.RaycastHit>), typeof(float)))
            {
                UnityEngine.Vector3    arg0 = ToLua.ToVector3(L, 1);
                UnityEngine.Vector3    arg1 = ToLua.ToVector3(L, 2);
                UnityEngine.RaycastHit arg2;
                float arg3 = (float)LuaDLL.lua_tonumber(L, 4);
                bool  o    = UnityEngine.Physics.Raycast(arg0, arg1, out arg2, arg3);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.Push(L, arg2);
                return(2);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Ray), typeof(LuaInterface.LuaOut <UnityEngine.RaycastHit>), typeof(float), typeof(int)))
            {
                UnityEngine.Ray        arg0 = ToLua.ToRay(L, 1);
                UnityEngine.RaycastHit arg1;
                float arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                int   arg3 = (int)LuaDLL.lua_tonumber(L, 4);
                bool  o    = UnityEngine.Physics.Raycast(arg0, out arg1, arg2, arg3);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.Push(L, arg1);
                return(2);
            }
            else if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3), typeof(LuaInterface.LuaOut <UnityEngine.RaycastHit>), typeof(float), typeof(int)))
            {
                UnityEngine.Vector3    arg0 = ToLua.ToVector3(L, 1);
                UnityEngine.Vector3    arg1 = ToLua.ToVector3(L, 2);
                UnityEngine.RaycastHit arg2;
                float arg3 = (float)LuaDLL.lua_tonumber(L, 4);
                int   arg4 = (int)LuaDLL.lua_tonumber(L, 5);
                bool  o    = UnityEngine.Physics.Raycast(arg0, arg1, out arg2, arg3, arg4);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.Push(L, arg2);
                return(2);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Physics.Raycast"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemple #56
0
    public bool Raycast(UnityEngine.Ray ray)
    {
        var bounds = new UnityEngine.Bounds();

        bounds.SetMinMax(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(_sizeX * 16, _sizeY * 16, _sizeZ * 16));

        // if we're outside world bounds, first intersect the world's bounding box
        if (!bounds.Contains(ray.origin))
        {
            float dist;
            if (!bounds.IntersectRay(ray, out dist))
            {
                return(false);
            }
            ray.origin += ray.direction * dist;
        }
        // inside or at world edge, time to voxel trace

        // From "A Fast Voxel Traversal Algorithm for Ray Tracing"
        // by John Amanatides and Andrew Woo, 1987
        // <http://www.cse.yorku.ca/~amana/research/grid.pdf>
        // <http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.42.3443>

        // initialize to initial voxel coordinate
        // TODO verify that this works reliable even if we started outside the world bounds
        int x = Mathf.FloorToInt(ray.origin.x);
        int y = Mathf.FloorToInt(ray.origin.y);
        int z = Mathf.FloorToInt(ray.origin.z);

        // TODO determine initial distances to voxel edges
        float tMaxX = intbound(ray.origin.x, ray.direction.x);
        float tMaxY = intbound(ray.origin.y, ray.direction.y);
        float tMaxZ = intbound(ray.origin.z, ray.direction.z);

        // determine stepping direction
        int stepX = (int)Mathf.Sign(ray.direction.x);
        int stepY = (int)Mathf.Sign(ray.direction.y);
        int stepZ = (int)Mathf.Sign(ray.direction.z);

        // determine distance (in ray units) between voxel edges
        float tDeltaX = stepX / ray.direction.x;
        float tDeltaY = stepY / ray.direction.y;
        float tDeltaZ = stepZ / ray.direction.z;

        int wx = _sizeX * 16;
        int wy = _sizeY * 16;
        int wz = _sizeZ * 16;

        while (
            (stepX > 0 ? x < wx : x >= 0) &&
            (stepY > 0 ? y < wy : y >= 0) &&
            (stepZ > 0 ? z < wz : z >= 0))
        {
            // lalala
            // TODO WE NOW HAVE A VOXEL AT X,Y,Z

            // walk...
            if (tMaxX < tMaxY)
            {
                if (tMaxX < tMaxZ)
                {
                    x     += stepX;
                    tMaxX += tDeltaX;
                }
                else
                {
                    z     += stepZ;
                    tMaxZ += tDeltaZ;
                }
            }
            else
            {
                if (tMaxY < tMaxZ)
                {
                    y     += stepY;
                    tMaxY += tDeltaY;
                }
                else
                {
                    z     += stepZ;
                    tMaxZ += tDeltaZ;
                }
            }
        }


        return(false);
    }
Exemple #57
0
 public bool Raycast(UnityEngine.Ray ray, out UnityEngine.RaycastHit hitInfo, float distance, int layerMask)
 {
     return(Physics.Raycast(ray, out hitInfo, distance, layerMask));
 }
    private UnityEngine.Vector2 ProjectPointer(float x, float y)
    {
        if (_texture == null)
        {
            return(new UnityEngine.Vector2(x, UnityEngine.Screen.height - y));
        }
        else
        {
            // Project using texture coordinates

            // First try with Unity GUI RawImage objects
            UnityEngine.EventSystems.EventSystem eventSystem = UnityEngine.EventSystems.EventSystem.current;

            if (eventSystem != null && eventSystem.IsPointerOverGameObject())
            {
                UnityEngine.Vector2 pos = new UnityEngine.Vector2(x, y);

                if (_pointerData == null)
                {
                    _pointerData = new UnityEngine.EventSystems.PointerEventData(eventSystem)
                    {
                        pointerId = 0,
                        position  = pos
                    };
                }
                else
                {
                    _pointerData.Reset();
                }

                _pointerData.delta    = pos - _pointerData.position;
                _pointerData.position = pos;

                UnityEngine.RectTransform rect = GetComponent <UnityEngine.RectTransform>();

                if (rect != null &&
                    UnityEngine.RectTransformUtility.ScreenPointToLocalPointInRectangle(
                        rect, _pointerData.position, _pointerData.pressEventCamera, out pos))
                {
                    UnityEngine.Vector2 pivot = new UnityEngine.Vector2(
                        rect.pivot.x * rect.rect.width,
                        rect.pivot.y * rect.rect.height);

                    float texCoordX = (pos.x + pivot.x) / rect.rect.width;
                    float texCoordY = (pos.y + pivot.y) / rect.rect.height;

                    float localX = _texture.width * texCoordX;
                    float localY = _texture.height * (1.0f - texCoordY);
                    return(new UnityEngine.Vector2(localX, localY));
                }
            }

            // NOTE: A MeshCollider must be attached to the target to obtain valid
            // texture coordintates, otherwise Hit Testing won't work

            UnityEngine.Ray ray = UnityEngine.Camera.main.ScreenPointToRay(new UnityEngine.Vector3(x, y, 0));

            UnityEngine.RaycastHit hit;
            if (UnityEngine.Physics.Raycast(ray, out hit))
            {
                if (hit.collider.gameObject == gameObject)
                {
                    float localX = _texture.width * hit.textureCoord.x;
                    float localY = _texture.height * (1.0f - hit.textureCoord.y);
                    return(new UnityEngine.Vector2(localX, localY));
                }
            }

            return(new UnityEngine.Vector2(-1, -1));
        }
    }
 /// <summary>Calcule la distance absolue entre une droite et un plan. Vaut 0 si ils ne sont pas parallèles.</summary>
 public static float Dist(Line l, Plane p)
 {
     return(Dist(p, l));
 }
Exemple #60
0
 public bool Raycast(UnityEngine.Ray ray, out UnityEngine.RaycastHit hitInfo)
 {
     return(Physics.Raycast(ray, out hitInfo));
 }