diff --git a/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts b/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts index eaab0ef..bcb0281 100644 --- a/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts +++ b/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts @@ -1,4 +1,4 @@ -import { _decorator, instantiate, ProgressBar, Label } from 'cc'; +import { _decorator, instantiate, ProgressBar, Label, Vec3, Tween, tween } from 'cc'; import { EntityManager } from '../../Base/EntityManager'; import { ApiMsgEnum, EntityTypeEnum, IActor, InputTypeEnum, IVec2, toFixed } from '../../Common'; import { EntityStateEnum } from '../../Enum'; @@ -27,6 +27,9 @@ export class ActorManager extends EntityManager implements IActor { private label: Label private weapon: WeaponManager + private tw: Tween + private targetPos: Vec3 + get isSelf() { return DataManager.Instance.myPlayerId === this.id } @@ -85,7 +88,21 @@ export class ActorManager extends EntityManager implements IActor { } renderPosition(data: IActor) { - this.node.setPosition(data.position.x, data.position.y) + // this.node.setPosition(data.position.x, data.position.y) + + const newPos = new Vec3(data.position.x, data.position.y) + if (!this.targetPos) { + this.node.setPosition(newPos) + this.targetPos = new Vec3() + this.targetPos.set(newPos) + } else if (!this.targetPos.equals(newPos)) { + this.tw?.stop() + this.node.setPosition(this.targetPos) + this.targetPos.set(newPos) + this.tw = tween(this.node).to(0.1, { + position: this.targetPos + }).start() + } } renderDirection(data: IActor) { diff --git a/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts b/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts index 79dc292..82ff92d 100644 --- a/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts +++ b/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts @@ -1,4 +1,4 @@ -import { _decorator } from 'cc' +import { Tween, tween, Vec3, _decorator } from 'cc' import { EntityManager } from '../../Base/EntityManager' import { EntityTypeEnum, IBullet, IVec2 } from '../../Common' import { EntityStateEnum, EventEnum } from '../../Enum' @@ -22,6 +22,8 @@ export class BulletManager extends EntityManager implements IBullet { direction: IVec2 private angle: number + private tw: Tween + private targetPos: Vec3 = new Vec3 init({ id, owner, type }: IBullet) { this.id = id @@ -54,13 +56,26 @@ export class BulletManager extends EntityManager implements IBullet { } render(data: IBullet) { - this.node.active = true this.renderPosition(data) this.renderDirection(data) } renderPosition(data: IBullet) { - this.node.setPosition(data.position.x, data.position.y) + const newPos = new Vec3(data.position.x, data.position.y) + if (!this.node.active) { + this.node.active = true + this.node.setPosition(newPos) + this.targetPos.set(newPos) + } else if (!this.targetPos.equals(newPos)) { + this.tw?.stop() + this.node.setPosition(this.targetPos) + this.targetPos.set(newPos) + this.tw = tween(this.node).to(0.1, { + position: this.targetPos + }).start() + } + + // this.node.setPosition(data.position.x, data.position.y) } renderDirection(data: IBullet) {