private void LinkToPlanet(RaycastHit hit) { var lastPlanet = _onPlanet; _onPlanet = hit.transform; // change status based on distance to ground Status = hit.distance < GroundMinimumDistance ? StickStatus.OnGround : (Status | StickStatus.Flying) & ~StickStatus.OnGround; // change of active planet Status |= _onPlanet != lastPlanet && hit.distance >= GroundMinimumDistance ? StickStatus.ChangingPlanet : Status; if ((_actorStatus.MoveDirection & ActorStatus.MovingTo.Down) > 0) { Status = Status & ~StickStatus.ChangingPlanet; } if ((Status & StickStatus.ChangingPlanet) > 0) { } // change normal with closest planet body hit if (_onPlanet == lastPlanet) { PlanetCurrentNormal = hit.normal; } }
private void LateUpdate() { _downDirection = transform.TransformDirection(Vector3.down); var notStranded = false; // link ray from transform to ground if (Physics.Raycast(transform.position, _downDirection, out _hitDown, LinkToPlanetDistance, _planetLayer)) { notStranded = true; // change status based on distance to ground Status = _hitDown.distance < GroundMinimumDistance ? StickStatus.OnGround : (Status | StickStatus.Flying) & ~StickStatus.OnGround; // normal extracted from ground hit PlanetCurrentNormal = _hitDown.normal; } // link ray from transform to whatever is on it if (Physics.Raycast(transform.position, transform.up, out _hitUp, LinkToPlanetDistance, _planetLayer)) { if (_hitUp.distance > _hitDown.distance || (Status & StickStatus.OnGround) > 0) { return; } Debug.Log(_hitUp); } Status = notStranded ? Status : StickStatus.Stranded; }
/// <summary> /// Just the animation for swinging the stick /// </summary> IEnumerator StickSwingRoutine() { swingState = StickStatus.Swinging; stick.SetActive(true); for (float timeLeft = swingTime; timeLeft > 0; timeLeft -= Time.deltaTime) { DebugAnimateStick(timeLeft); yield return(null); } stick.SetActive(false); swingState = StickStatus.Idle; }
// [SerializeField] GameObject stickHitParticles; // [SerializeField] AnimationCurve debugStickAnimation; void OnEnable() { swingState = StickStatus.Idle; stick.SetActive(false); if (TouchManager.inst != null) { TouchManager.inst.OnNewFinger += OnNewFinger; } else { lateStartTouchManager = true; } }