private void CalculateHorizontalInput() { Vector3 MousePosition = PlayerEyes.GetEyesWorldLocation(); Vector3 PlayerCenter = playerTransform.position; PlayerCenter.y = MousePosition.y; float distance = Vector3.Distance(PlayerCenter, MousePosition); float angle = Vector3.Angle(PlayerCenter, MousePosition); Camera cam = Camera.main; Vector2 screen = cam.WorldToScreenPoint(MousePosition); /*if (distance > _xThresholdRight) * { * playerTransform.Rotate(Vector3.up * _rotationSpeed * Time.deltaTime); * } * else if (distance < _xThresholdLeft) * { * playerTransform.Rotate(Vector3.up * -_rotationSpeed * Time.deltaTime); * } * * if (angle > 70.0f) * { * playerTransform.Rotate(Vector3.up * _rotationSpeed * Time.deltaTime); * } * * if (angle < 40.0f) * { * playerTransform.Rotate(Vector3.up * -1 * _rotationSpeed * Time.deltaTime); * }*/ }
private void FireProjectile() { if (Time.time - _lastFireTime < _fireRate) { return; } _AudioSource.Play(); var projectile = _projectiles.ElementAt(_currentIndex++); if (_currentIndex >= _projectiles.Count) { _currentIndex = 0; } projectile.transform.position = _fireSocket.position; projectile.gameObject.SetActive(true); var eyesPosition = PlayerEyes.GetWorldLocation(); var direction = eyesPosition - transform.position; projectile.Fire(direction.normalized * _fireLaunchSpeed); _lastFireTime = Time.time; }
private void Update() { RaycastHit hit; var direction = (PlayerEyes.GetWorldLocation() - _fireSocket.transform.position).normalized; if (Physics.Raycast(new Ray(_fireSocket.transform.position, direction), out hit)) { _targetAimObject.transform.position = hit.point + hit.normal * 0.001f; _targetAimObject.transform.rotation = Quaternion.LookRotation(hit.normal); var command = hit.collider.GetComponentInParent <NPCCommandable>(); if (_commandInProgress && command != _commandInProgress) { _commandInProgress.SetFillAmount(0.0f); _progressAmount = 0.0f; } if (command) { _progressAmount = Mathf.MoveTowards(_progressAmount, 1.0f, Time.deltaTime * _fillAmountSpeed); command.SetFillAmount(_progressAmount); _commandInProgress = command; } if (Math.Abs(_progressAmount - 1.0f) < float.Epsilon) { CommandManager.Instance.CompleteProgress(_commandInProgress); _audioSource.time = 0.5f; _audioSource.Play(); } } }
private void Awake() { if (!_playerEyes) { _playerEyes = this; } }
private void CalculateVerticalInput() { //Vector3 MousePosition = PlayerEyes.GetEyesWorldLocation(); Vector2 MousePosition = PlayerEyes.GetEyesWorldLocation(); if (MousePosition.x > Screen.width - _maxThreshold && MousePosition.y > Screen.height - _maxThreshold) { return; } else if (MousePosition.x < _maxThreshold && MousePosition.y > Screen.height - _maxThreshold) { return; } else if (MousePosition.x > Screen.width - _maxThreshold && MousePosition.y < _maxThreshold) { return; } else if (MousePosition.x < _maxThreshold && MousePosition.y < _maxThreshold) { return; } if (MousePosition.x > Screen.width / 2 + _minThreshold) { playerTransform.Rotate(Vector3.up * _rotationSpeed * Time.deltaTime); } else if (MousePosition.x < Screen.width / 2 - _minThreshold) { playerTransform.Rotate(Vector3.up * -_rotationSpeed * Time.deltaTime); } else if (MousePosition.y > Screen.height / 2 + _minThreshold) { playerTransform.position += playerTransform.forward * Time.deltaTime * _movementSpeed; } else if (MousePosition.y < Screen.height / 2 - _minThreshold) { playerTransform.position += -playerTransform.forward * Time.deltaTime * _movementSpeed; } /*if (distance > _yThresholdUp) * { * playerTransform.Rotate(Vector3.up * _rotationSpeed * Time.deltaTime); * } * else if (distance < _yThresholdBottom) * { * playerTransform.Rotate(Vector3.up * -_rotationSpeed * Time.deltaTime); * } * * if (angle > 30.0f) * { * playerTransform.position += playerTransform.forward * Time.deltaTime * _movementSpeed; * } * * if (angle < 20.0f) * { * playerTransform.position += -playerTransform.forward * Time.deltaTime * _movementSpeed; * }*/ }
void Awake() { projectileDragging = GameObject.FindObjectOfType <ProjectileDragging>(); playerEyes = GameObject.FindObjectsOfType <PlayerEyes>(); //playerEyes = GetComponentsInChildren<PlayerEyes>(); playerEyesGO = GameObject.FindObjectOfType <PlayerEyes>(); eyesRenderer = GetComponentInChildren <SpriteRenderer>(); playerrb = GetComponent <Rigidbody2D>(); playerCollider = GetComponent <Collider2D>(); ccol2d = GetComponent <CircleCollider2D>(); trailRenderer = GetComponent <TrailRenderer>(); spriteRenderer = GetComponent <SpriteRenderer>(); //Sound Effects source = GetComponent <AudioSource>(); }
private void UpdateEyes() { _eyes.ForEach(eye => { var lookingDirection = PlayerEyes.GetWorldLocation() - transform.position; eye.transform.rotation = Quaternion.LookRotation(lookingDirection); var euler = eye.transform.localEulerAngles; eye.transform.localEulerAngles = new Vector3( //euler.x > 200 // ? Mathf.Clamp(euler.x, 360 + _pitchLimit.x, 360 + _pitchLimit.x) // : Mathf.Clamp(euler.x, _pitchLimit.x, _pitchLimit.x), Mathf.Clamp(euler.x, _pitchLimit.x, _pitchLimit.y), euler.y > 200 ? Mathf.Clamp(euler.y, 360 + _yawLimit.x, 360 + _yawLimit.y) : Mathf.Clamp(euler.y, _yawLimit.x, _yawLimit.y), euler.z ); }); }
private void Update() { if (PlayerEyes.GetWorldLocation() == Vector3.zero) { return; } var dir = PlayerEyes.GetWorldLocation() - _fireSocket.transform.position; var rot = Quaternion.LookRotation(dir).eulerAngles; var towerRot = _tower.transform.rotation.eulerAngles; towerRot.y = rot.y + 90.0f; _tower.transform.rotation = Quaternion.Euler(towerRot); var barrelRot = _barrel.transform.rotation.eulerAngles; barrelRot.x = rot.x - 90.0f; _barrel.transform.rotation = Quaternion.Euler(barrelRot); }
private void Update() { Debug.Log("Eye position : " + PlayerEyes.GetEyesWorldLocation()); CalculateVerticalInput(); CalculateHorizontalInput(); //transform.parent.parent.transform.position += transform.forward * Time.deltaTime * _movementSpeed; ; //transform.parent.parent.transform.position += transform.forward * Time.deltaTime * 100f; if (Input.GetKey(KeyCode.W)) { Debug.Log("ALLO"); playerTransform.position += playerTransform.forward * Time.deltaTime * _movementSpeed; } if (Input.GetKey(KeyCode.S)) { playerTransform.position += -playerTransform.forward * Time.deltaTime * _movementSpeed; } if (Input.GetKey(KeyCode.A)) { /*playerTransform.rotation = * Quaternion.LookRotation( * Vector3.RotateTowards(playerTransform.forward, -playerTransform.right, _rotationSpeed, 0.0f));*/ playerTransform.Rotate(Vector3.up * -1 * _rotationSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.D)) { /*playerTransform.rotation = * Quaternion.LookRotation(Vector3.RotateTowards(playerTransform.forward, playerTransform.right, _rotationSpeed, * 0.0f));*/ playerTransform.Rotate(Vector3.up * _rotationSpeed * Time.deltaTime); } }
private void Update() { _lineRenderer.SetPosition(0, _fireSocket.transform.position); _lineRenderer.SetPosition(1, PlayerEyes.GetWorldLocation()); _particleSystem.transform.position = PlayerEyes.GetWorldLocation(); var direction = (PlayerEyes.GetWorldLocation() - _fireSocket.transform.position).normalized; RaycastHit hit; if (Physics.Raycast(new Ray(_fireSocket.transform.position, direction), out hit)) { _particleSystem.transform.rotation = Quaternion.LookRotation(hit.normal); var puzzleElement = hit.collider.GetComponent <PuzzleElement2>(); if (puzzleElement && !_previousElement) { _previousElement = puzzleElement; _audioSource.Play(); } if (puzzleElement && _previousElement && puzzleElement != _previousElement) { _previousElement.ConnectTo(puzzleElement); _previousElement = puzzleElement; } if (_previousElement && !_previousElement.ConnectionSuccess && !_previousElement.Completed) { _previousElement.UpdateEndLine(hit.point); } } if (_audioSource.time > 0.5f) { _audioSource.Stop(); } }
private void TickOrientation(float delta, float time) { Quaternion quaternion; if (this.AiDomain == null || this.AiDomain.NpcContext == null) { return; } Vector3 headingDirection = base.transform.forward; switch (this.AiDomain.NpcContext.OrientationType) { case NpcOrientation.Heading: { headingDirection = this.AiDomain.GetHeadingDirection(); break; } case NpcOrientation.PrimaryTargetBody: { headingDirection = this.AiDomain.NpcContext.GetDirectionToPrimaryEnemyPlayerTargetBody(); break; } case NpcOrientation.PrimaryTargetHead: { headingDirection = this.AiDomain.NpcContext.GetDirectionToPrimaryEnemyPlayerTargetHead(); break; } case NpcOrientation.LastKnownPrimaryTargetLocation: { headingDirection = this.AiDomain.NpcContext.GetDirectionToMemoryOfPrimaryEnemyPlayerTarget(); break; } case NpcOrientation.LookAround: { headingDirection = this.AiDomain.NpcContext.GetDirectionLookAround(); break; } case NpcOrientation.LastAttackedDirection: { headingDirection = this.AiDomain.NpcContext.GetDirectionLastAttackedDir(); break; } case NpcOrientation.AudibleTargetDirection: { headingDirection = this.AiDomain.NpcContext.GetDirectionAudibleTarget(); break; } case NpcOrientation.LookAtAnimal: { headingDirection = this.AiDomain.NpcContext.GetDirectionToAnimal(); break; } case NpcOrientation.Home: { headingDirection = this.AiDomain.GetHomeDirection(); break; } default: { return; } } if (Mathf.Approximately(headingDirection.sqrMagnitude, 0f)) { return; } BaseEntity parentEntity = base.GetParentEntity(); if (!parentEntity) { this.eyes.bodyRotation = Quaternion.LookRotation(headingDirection, base.transform.up); if (this.OnlyRotateAroundYAxis) { PlayerEyes playerEye = this.eyes; quaternion = this.eyes.bodyRotation; playerEye.bodyRotation = Quaternion.Euler(new Vector3(0f, quaternion.eulerAngles.y, 0f)); } this.ServerRotation = this.eyes.bodyRotation; return; } Vector3 vector3 = parentEntity.transform.InverseTransformDirection(headingDirection); Vector3 vector31 = new Vector3(headingDirection.x, vector3.y, headingDirection.z); this.eyes.rotation = Quaternion.LookRotation(vector31, parentEntity.transform.up); if (this.OnlyRotateAroundYAxis) { PlayerEyes playerEye1 = this.eyes; quaternion = this.eyes.rotation; playerEye1.rotation = Quaternion.Euler(new Vector3(0f, quaternion.eulerAngles.y, 0f)); } this.ServerRotation = this.eyes.bodyRotation; }
public void Start() { //get spriterenderer components of each character part //(use these .sprite attributes to set sprites) SpriteRenderer BodySprite = PlayerBody.GetComponent <SpriteRenderer>(); SpriteRenderer EyesSprite = PlayerEyes.GetComponent <SpriteRenderer>(); SpriteRenderer MouthSprite = PlayerMouth.GetComponent <SpriteRenderer>(); SpriteRenderer HairSprite = PlayerHair.GetComponent <SpriteRenderer>(); SpriteRenderer ClothesSprite = PlayerClothes.GetComponent <SpriteRenderer>(); SpriteRenderer HatSprite = PlayerHat.GetComponent <SpriteRenderer>(); SpriteRenderer AnimalSprite = PlayerAnimal.GetComponent <SpriteRenderer>(); //check all parts //body switch (PlayerPrefs.GetInt("PlayerBody", 0)) { case (0): BodySprite.sprite = Body1; break; case (1): BodySprite.sprite = Body2; break; case (2): BodySprite.sprite = Body3; break; case (3): BodySprite.sprite = Body4; break; } //eyes switch (PlayerPrefs.GetInt("PlayerEyes", 0)) { case (0): EyesSprite.sprite = Eyes1; break; case (1): EyesSprite.sprite = Eyes2; break; case (2): EyesSprite.sprite = Eyes3; break; case (3): EyesSprite.sprite = Eyes4; break; } //mouth switch (PlayerPrefs.GetInt("PlayerMouth", 0)) { case (0): MouthSprite.sprite = Mouth1; break; case (1): MouthSprite.sprite = Mouth2; break; } //hair switch (PlayerPrefs.GetInt("PlayerHair", 0)) { case (0): HairSprite.sprite = Hair1; break; case (1): break; } //clothes switch (PlayerPrefs.GetInt("PlayerClothes", 0)) { case (0): ClothesSprite.sprite = Robe1Red; break; case (1): ClothesSprite.sprite = Robe1Blue; break; case (2): ClothesSprite.sprite = Robe1Green; break; case (3): ClothesSprite.sprite = Robe1Grey; break; case (4): ClothesSprite.sprite = Robe1Orange; break; case (5): ClothesSprite.sprite = Robe1Purple; break; case (6): ClothesSprite.sprite = Robe2Red; break; case (7): ClothesSprite.sprite = Robe2Blue; break; case (8): ClothesSprite.sprite = Robe2Green; break; case (9): ClothesSprite.sprite = Robe2Grey; break; case (10): ClothesSprite.sprite = Robe2Orange; break; case (11): ClothesSprite.sprite = Robe2Purple; break; case (12): ClothesSprite.sprite = Robe3Red; break; case (13): ClothesSprite.sprite = Robe3Blue; break; case (14): ClothesSprite.sprite = Robe3Green; break; case (15): ClothesSprite.sprite = Robe3Grey; break; case (16): ClothesSprite.sprite = Robe3Orange; break; case (17): ClothesSprite.sprite = Robe3Purple; break; case (18): ClothesSprite.sprite = Clothes1; break; } //hat switch (PlayerPrefs.GetInt("PlayerHat", 0)) { case (0): HatSprite.sprite = Hat1; break; case (1): break; } //animal switch (PlayerPrefs.GetInt("PlayerAnimal", 0)) { case (0): AnimalSprite.sprite = Bunny; break; case (1): AnimalSprite.sprite = Turtle; break; } }
private bool AreEyesOver() { var eyesLocation = _image.rectTransform.InverseTransformPoint(PlayerEyes.GetEyesLocation()); return(_activation.rectTransform.rect.Contains(eyesLocation)); }
private void Awake() { _maskSwitch = GetComponent <MaskSwitch>(); glowingEyes = GetComponentInChildren <PlayerEyes>(); }
private void TickOrientation(float delta, float time) { if (Object.op_Equality((Object)this.AiDomain, (Object)null) || this.AiDomain.NpcContext == null) { return; } ((Component)this).get_transform().get_forward(); Vector3 vector3_1; switch (this.AiDomain.NpcContext.OrientationType) { case NpcOrientation.Heading: vector3_1 = this.AiDomain.GetHeadingDirection(); break; case NpcOrientation.PrimaryTargetBody: vector3_1 = this.AiDomain.NpcContext.GetDirectionToPrimaryEnemyPlayerTargetBody(); break; case NpcOrientation.PrimaryTargetHead: vector3_1 = this.AiDomain.NpcContext.GetDirectionToPrimaryEnemyPlayerTargetHead(); break; case NpcOrientation.LastKnownPrimaryTargetLocation: vector3_1 = this.AiDomain.NpcContext.GetDirectionToMemoryOfPrimaryEnemyPlayerTarget(); break; case NpcOrientation.LookAround: vector3_1 = this.AiDomain.NpcContext.GetDirectionLookAround(); break; case NpcOrientation.LastAttackedDirection: vector3_1 = this.AiDomain.NpcContext.GetDirectionLastAttackedDir(); break; case NpcOrientation.AudibleTargetDirection: vector3_1 = this.AiDomain.NpcContext.GetDirectionAudibleTarget(); break; case NpcOrientation.LookAtAnimal: vector3_1 = this.AiDomain.NpcContext.GetDirectionToAnimal(); break; case NpcOrientation.Home: vector3_1 = this.AiDomain.GetHomeDirection(); break; default: return; } if (Mathf.Approximately(((Vector3) ref vector3_1).get_sqrMagnitude(), 0.0f)) { return; } BaseEntity parentEntity = this.GetParentEntity(); if (Object.op_Implicit((Object)parentEntity)) { Vector3 vector3_2 = ((Component)parentEntity).get_transform().InverseTransformDirection(vector3_1); Vector3 vector3_3; ((Vector3) ref vector3_3).\u002Ector((float)vector3_1.x, (float)vector3_2.y, (float)vector3_1.z); this.eyes.rotation = Quaternion.LookRotation(vector3_3, ((Component)parentEntity).get_transform().get_up()); if (this.OnlyRotateAroundYAxis) { PlayerEyes eyes = this.eyes; Quaternion rotation = this.eyes.rotation; Quaternion quaternion = Quaternion.Euler(new Vector3(0.0f, (float)((Quaternion) ref rotation).get_eulerAngles().y, 0.0f)); eyes.rotation = quaternion; } this.ServerRotation = this.eyes.bodyRotation; } else { this.eyes.bodyRotation = Quaternion.LookRotation(vector3_1, ((Component)this).get_transform().get_up()); if (this.OnlyRotateAroundYAxis) { PlayerEyes eyes = this.eyes; Quaternion bodyRotation = this.eyes.bodyRotation; Quaternion quaternion = Quaternion.Euler(new Vector3(0.0f, (float)((Quaternion) ref bodyRotation).get_eulerAngles().y, 0.0f)); eyes.bodyRotation = quaternion; } this.ServerRotation = this.eyes.bodyRotation; } }