protected override void OnUpdate() { for (int i = 0; i < FollowEntities.Length; i++) { Transform trans = FollowEntities.Transforms[i]; FollowComponent fc = FollowEntities.FollowComponents[i]; VelocityComponent vc = FollowEntities.VelocityComponents[i]; Vector3 direction = trans.InverseTransformDirection(fc.followTrans.position - trans.position); if (direction.magnitude < fc.stopDistance) { vc.inputX = Mathf.Lerp(vc.inputX, 0, Time.deltaTime * 3); vc.inputY = Mathf.Lerp(vc.inputY, 0, Time.deltaTime * 3); } else { direction.Normalize(); vc.inputX = Mathf.Lerp(vc.inputX, direction.x, Time.deltaTime * 3); vc.inputY = Mathf.Lerp(vc.inputY, direction.z, Time.deltaTime * 3); } } for (int i = 0; i < LookAtEntities.Length; i++) { Transform trans = LookAtEntities.Transforms[i]; LookAtComponent lookAt = LookAtEntities.LookAtComponents[i]; HeadingComponent heading = LookAtEntities.HeadingComponents[i]; Vector3 direction = lookAt.lookTrans.position - trans.position; trans.rotation = Quaternion.Lerp(trans.rotation, Quaternion.LookRotation(direction), Time.deltaTime * heading.angularSpeed); } }
/// <summary> /// Creates a new <see cref="MonsterEntity"/> instance. /// </summary> /// <param name="context"></param> public MonsterEntity() { Moves = new MovableComponent(); Timers = new TimerComponent(); Follow = new FollowComponent(); Interaction = new InteractionComponent(); Battle = new BattleComponent(); Attributes = new AttributeComponent(); }
/// <summary> /// Creates a new <see cref="NpcEntity"/> instance. /// </summary> /// <param name="context"></param> public NpcEntity() { Object.Type = WorldObjectType.Mover; Timers = new TimerComponent(); Interaction = new InteractionComponent(); Battle = new BattleComponent(); Attributes = new AttributeComponent(); Moves = new MovableComponent(); Follow = new FollowComponent(); }
protected override Vector3 GetFinalPos(Entity entity, FollowComponent follow) { var mis = entity.GetCustomComponent <MouseInputComponent>(); if (mis.target.point != Vector3.zero) //鼠标出游戏窗口后目标位置是(0,0,0) { follow.targetPoint = mis.target.point; } return(new Vector3(follow.targetPoint.x, 0, follow.targetPoint.z)); }
/// <summary> /// Creates a new <see cref="PlayerEntity"/> instance. /// </summary> /// <param name="context"></param> public PlayerEntity(IPlayerFactory playerFactory) { Moves = new MovableComponent(); PlayerData = new PlayerDataComponent(); Taskbar = new TaskbarComponent(); Follow = new FollowComponent(); Interaction = new InteractionComponent(); Battle = new BattleComponent(); Timers = new TimerComponent(); Attributes = new AttributeComponent(); QuestDiary = new QuestDiaryComponent(); SkillTree = new SkillTreeComponent(); Inventory = new InventoryContainerComponent(); _playerFactory = playerFactory; }
protected override void Move(Entity entity, FollowComponent follow) { var rigid = entity.GetComponent <Rigidbody>(); var force = new float3(); var calculate = new CalculateForce() { tar = follow.targetPoint, pos = entity.transform.position, velocity = rigid.velocity, result = &force }; calculate.Schedule().Complete(); rigid.AddForce(force); }
protected override Vector3 GetFinalPos(Entity entity, FollowComponent follow) { var position = follow.targetTrans.position; return(new Vector3(position.x, follow.height, position.z - 9.5F + math.tan(90 - follow.degree) * follow.height)); }
protected override void Move(Entity entity, FollowComponent follow) { //entity.transform.DOMove(follow.targetPoint, 0); entity.transform.position = follow.targetPoint; }
protected abstract void Move(Entity entity, FollowComponent follow);
protected abstract Vector3 GetFinalPos(Entity entity, FollowComponent follow);