public OrbitWalker GetOrbitWalker() { if (_orbitWalker == null) { _orbitWalker = new OrbitWalker { Id = gameObject.GetInstanceID(), Transform = transform, CurAngle = StartAngle, OrbitRadius = OrbitRadius, AngularSpeed = AngularSpeed, }; } return(_orbitWalker); }
private void UpdatePosition(OrbitWalker walker, float deltaTime) { walker.CurAngle += walker.AngularSpeed * deltaTime; var radians = walker.CurAngle * Mathf.Deg2Rad; Vector2 newPos = new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)); newPos = newPos * walker.OrbitRadius + _center; var prevPos = walker.Transform.localPosition; walker.Transform.localPosition = newPos; var moveDir = (walker.Transform.localPosition - prevPos).normalized; walker.Transform.localRotation = Quaternion.LookRotation(moveDir); }
public void Add(OrbitWalker orbitWalker) { _walkers.Add(orbitWalker.Id, orbitWalker); }