技能碰撞改回物理碰撞
This commit is contained in:
@@ -8,6 +8,7 @@ import { AnimType, endType, SkillSet } from "../common/config/SkillSet";
|
||||
import { EndAnmCom } from './EndAnmCom';
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { HeroFac, HeroSet } from "../common/config/heroSet";
|
||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -36,11 +37,11 @@ export class SkillCom extends CCComp {
|
||||
animName: string = "";
|
||||
group:number = 0; //阵营
|
||||
fac:number=0; //阵营
|
||||
rigid:RigidBody2D=null!; // 动画名称
|
||||
target:any=null;
|
||||
caster:any=null;
|
||||
distance_x:number=0;
|
||||
distance_y:number=0;
|
||||
ap:number=0;
|
||||
private moveDirection: Vec3 | null = null; // 添加一个属性来存储移动方向
|
||||
|
||||
protected onLoad(): void {
|
||||
@@ -51,19 +52,12 @@ export class SkillCom extends CCComp {
|
||||
start() {
|
||||
oops.message.on(GameEvent.MissionEnd, this.doDestroy, this);
|
||||
this.node.active = true;
|
||||
// let collider = this.getComponent(Collider2D);
|
||||
// console.log(this.group +"技能 collider ",collider);
|
||||
// collider.group = this.group;
|
||||
// if (collider) {
|
||||
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
|
||||
// }
|
||||
// this.rigid = this.getComponent(RigidBody2D);
|
||||
// if(this.rigid.sleep){
|
||||
// console.log(this.scale+"技能 rigid sleep ",this.rigid);
|
||||
// this.rigid.wakeUp();
|
||||
// }
|
||||
// 根据动画类型开始相应的运动
|
||||
let collider = this.getComponent(Collider2D);
|
||||
console.log(this.group +"技能 collider ",collider);
|
||||
collider.group = this.group;
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
let dir_x = this.target.node.position.x > this.node.position.x ? 1 : -1
|
||||
this.node.scale = v3(dir_x,1,1)
|
||||
// 根据目标位置设置节点朝向
|
||||
@@ -104,9 +98,35 @@ export class SkillCom extends CCComp {
|
||||
|
||||
this.startMovement();
|
||||
}
|
||||
// onBeginContact (seCol: Collider2D, oCol: Collider2D) {
|
||||
// console.log(this.scale+"碰撞开始 ",seCol,oCol);
|
||||
// }
|
||||
onBeginContact (seCol: Collider2D, oCol: Collider2D) {
|
||||
console.log(this.scale+"碰撞开始 ",seCol,oCol);
|
||||
let target = oCol.getComponent(HeroViewComp)
|
||||
let caster = seCol.getComponent(HeroViewComp)
|
||||
if(oCol.group!=this.group){
|
||||
if(target == null) return;
|
||||
let remainingDamage = this.ap;
|
||||
if (target.shield > 0) {
|
||||
target.shield -= 1
|
||||
target.BUFFCOMP.tooltip(5,"*吸收*");
|
||||
remainingDamage = 0
|
||||
if (target.shield <= 0) {
|
||||
if(target == null) return;
|
||||
target.BUFFCOMP.show_shield(false);
|
||||
}
|
||||
}else{
|
||||
if(target == null) return;
|
||||
target.hp -= remainingDamage;
|
||||
if(target.hp <= 0) {
|
||||
if(target == null) return;
|
||||
target.BUFFCOMP.dead()
|
||||
if(target.ent == null) return;
|
||||
target.ent.destroy();
|
||||
}
|
||||
target.showDamage(remainingDamage, true);
|
||||
}
|
||||
this.ent.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -244,7 +264,6 @@ export class SkillCom extends CCComp {
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.is_destroy = false;
|
||||
this.node.destroy();
|
||||
this.animType = 0;
|
||||
this.endType = 0;
|
||||
this.speed = 0;
|
||||
@@ -252,6 +271,14 @@ export class SkillCom extends CCComp {
|
||||
this.startPos.set();
|
||||
this.targetPos.set();
|
||||
this.moveDirection = null; // 重置移动方向
|
||||
// 先移除所有碰撞回调
|
||||
const collider = this.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
collider.off(Contact2DType.BEGIN_CONTACT);
|
||||
}
|
||||
this.scheduleOnce(() => {
|
||||
this.node.destroy();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user