private void RaycastBounce(int bounces, Vector3 origin, Vector3 dir) { if (bounces == 0) { return; } Vector2 _dir = AngularTweeks.DirectionOffset(playerForwardSide); Ray _rayOrigin = new Ray(origin, _dir); RaycastHit _hitInfo; Debug.DrawRay(origin, _dir, Color.green, Mathf.Infinity); if (Physics.Raycast(_rayOrigin, out _hitInfo, 1000f)) { Debug.Log("hit"); ShootingTarget _st = _hitInfo.transform.GetComponent <ShootingTarget>(); if (_st != null) { _st.GetShot(gunData); Vector3 bounceDir = Vector3.Reflect(_dir, _hitInfo.normal); RaycastBounce(gunData.bounces - 1, _hitInfo.point, bounceDir); } } }
public override void Disparar(Transform transform) { Vector3 _dir = AngularTweeks.DirectionOffset(playerForwardSide); _dir = transform.TransformDirection(_dir); Ray _origin = new Ray(transform.position, _dir); RaycastHit _hitInfo; Debug.DrawRay(transform.position, _dir, Color.green, Mathf.Infinity); if (Physics.Raycast(_origin, out _hitInfo, 1000f)) { Debug.Log("Hit"); ShootingTarget _st = _hitInfo.transform.GetComponent <ShootingTarget>(); if (_st != null) { _st.GetShot(gunData); Vector3 bounceDir = Vector3.Reflect(_dir, _hitInfo.normal); RaycastBounce(gunData.bounces - 1, _hitInfo.point, bounceDir); } } }
// Update is called once per frame void Update() { Vector3 vectorToTarget = target.position - transform.position; float angle = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg - AngularTweeks.AngleOffset(this.forwardSide); Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward); transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * rotationSpeed); }
private void Update() { Vector3 moveDirection = transform.position - _orgPosition; float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg - AngularTweeks.AngleOffset(forwardSide); transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); Debug.Log(rb.velocity.magnitude); }