UnityEngine.Physics.Linecast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit)

Here are the examples of the csharp api UnityEngine.Physics.Linecast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

19 View Source File : ItemBlasterBolt.cs
License : GNU General Public License v3.0
Project Creator : Kingo64

void Deflectreplacedist() {
            if (GlobalSettings.LightsaberColliders.Count > 0) {
                List<int> toRemove = null;
                var currentPos = body.transform.position;
                var hasBeenreplacedisted = false;
                foreach (KeyValuePair<int, Collider[]> colliders in GlobalSettings.LightsaberColliders) {
                    if (hasBeenreplacedisted) return;
                    foreach (var collider in colliders.Value) {
                        if (!collider) {
                            if (toRemove == null) toRemove = new List<int> { colliders.Key };
                            else toRemove.Add(colliders.Key);
                            break;
                        }
                        if (collider.enabled) {
                            var closest = collider.ClosestPoint(currentPos);
                            if (Mathf.Abs((currentPos - closest).sqrMagnitude) < GlobalSettings.SaberDeflectreplacedistDistance) {
                                hasBeenreplacedisted = true;
                                var lastHandler = item.lastHandler;
                                if (GlobalSettings.SaberDeflectreplacedistAlwaysReturn && (GlobalSettings.SaberDeflectreplacedistAlwaysReturnNPC || !lastHandler || lastHandler.creature != Player.currentCreature)) {
                                    if (item.lastHandler) {
                                        var direction = item.lastHandler.creature.ragdoll.GetPart(Utils.RandomEnum<RagdollPart.Type>()).transform.position - transform.position;
                                        body.velocity = direction.normalized * body.velocity.magnitude;
                                    } else {
                                        body.velocity *= -1;
                                    }
                                    var blasterCollider = GetComponentInChildren<Collider>();
                                    var collision = new CollisionInstance();
                                    collision.sourceCollider = blasterCollider;
                                    collision.targetCollider = collider;
                                    collision.contactPoint = closest;
                                    if (Physics.Linecast(transform.position, closest, out RaycastHit hit)) {
                                        collision.contactNormal = hit.normal;
                                    }
                                    MaterialData.TryGetMaterials(Animator.StringToHash(blasterCollider.material.name), Animator.StringToHash(collider.material.name), out MaterialData sourceMaterial, out MaterialData targetMaterial);
                                    if (collision.SpawnEffect(sourceMaterial, targetMaterial, false, out EffectInstance effect)) {
                                        effect.SetIntensity(Random.Range(0.06f, 0.12f));
                                        effect.Play();
                                    }
                                    debounceTime = 0.1f;
                                } else {
                                    if (Time.timeScale >= 1 ) body.position = closest;
                                    body.velocity = (currentPos - closest).normalized * body.velocity.magnitude;
                                }
                            }
                        }
                    }
                }
                if (toRemove != null) {
                    foreach (var key in toRemove) {
                        GlobalSettings.LightsaberColliders.Remove(key);
                    }
                }
            }
        }

19 View Source File : Example.cs
License : GNU General Public License v3.0
Project Creator : KleskBY

private bool IsVisable(GameObject origin, Vector3 toCheck)
    {
        RaycastHit hit;
        if (Physics.Linecast(Camera.main.transform.position, toCheck, out hit))
        {
            if (hit.transform.name.Contains("NPC") || hit.transform.name.Contains("client")
                || hit.transform.name == Camera.main.name || hit.transform.name == Camera.main.gameObject.name 
                || hit.transform.name == Camera.main.transform.name || hit.transform.tag.Contains("Player"))
            {
                return true;
            }
        }
        return false;
    }

19 View Source File : ETCBase.cs
License : MIT License
Project Creator : XINCGer

protected void CameraSmoothFollow(){

		if (!cameraTransform  ||  !cameraLookAt ) return ;


		float wantedRotationAngle = cameraLookAt.eulerAngles.y;
		float wantedHeight = cameraLookAt.position.y + followHeight;
		
		float currentRotationAngle = cameraTransform.eulerAngles.y;
		float currentHeight = cameraTransform.position.y;

		currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, followRotationDamping * Time.deltaTime);
		currentHeight = Mathf.Lerp(currentHeight, wantedHeight, followHeightDamping * Time.deltaTime);

		Quaternion currentRotation = Quaternion.Euler(0, currentRotationAngle, 0);

		Vector3 newPos = cameraLookAt.position;
		newPos -= currentRotation * Vector3.forward * followDistance;
		newPos = new Vector3(newPos.x ,currentHeight , newPos.z);

		if (enableWallDetection){
			RaycastHit wallHit;

			if (Physics.Linecast( new Vector3(cameraLookAt.position.x,cameraLookAt.position.y+1f,cameraLookAt.position.z),newPos, out wallHit)){
				newPos= new Vector3( wallHit.point.x, currentHeight,wallHit.point.z);
			}
		}
		cameraTransform.position = newPos;
		cameraTransform.LookAt(cameraLookAt);
		
	}