dd
This commit is contained in:
@@ -18,7 +18,6 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('SkillCom')
|
||||
@ecs.register('SkillCom')
|
||||
export class SkillCom extends CCComp {
|
||||
BezierMove:BezierMove=null!;
|
||||
s_uuid:number = 0;
|
||||
s_name:string = "";
|
||||
hero:number = 0;
|
||||
@@ -50,7 +49,7 @@ export class SkillCom extends CCComp {
|
||||
}
|
||||
|
||||
start() {
|
||||
this.BezierMove=this.node.getComponent(BezierMove)
|
||||
|
||||
oops.message.on(GameEvent.MissionEnd, this.doDestroy, this);
|
||||
this.node.active = true;
|
||||
let collider = this.getComponent(Collider2D);
|
||||
@@ -59,44 +58,52 @@ export class SkillCom extends CCComp {
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
let dir_x = this.targetPos.x > this.node.position.x ? 1 : -1
|
||||
this.node.scale = v3(dir_x,1,1)
|
||||
|
||||
if(SkillSet[this.s_uuid].AnimType==AnimType.parabolic){
|
||||
let bm=this.node.getComponent(BezierMove)
|
||||
// bm.speed=700
|
||||
if(this.group==BoxSet.MONSTER) bm.controlPointSide=-1
|
||||
bm.moveTo(this.targetPos)
|
||||
}
|
||||
|
||||
// let dir_x = this.targetPos.x > this.node.position.x ? 1 : -1
|
||||
// this.node.scale = v3(dir_x,1,1)
|
||||
// 根据目标位置设置节点朝向
|
||||
if ( this.targetPos) {
|
||||
// 计算朝向
|
||||
let direction = this.targetPos.x > this.node.position.x ? 1 : -1;
|
||||
// 设置节点缩放来改变朝向
|
||||
this.node.scale = v3(direction * Math.abs(this.scale), this.scale, 1);
|
||||
}
|
||||
let dir_y = ( this.targetPos.y+BoxSet.ATK_Y) > this.node.position.y ? 1 : -1
|
||||
if( this.targetPos.y+BoxSet.ATK_Y==this.node.position.y){
|
||||
dir_y=0
|
||||
}
|
||||
// 计算这一帧的移动距离
|
||||
this.distance_x = SkillSet[this.s_uuid].speed*dir_x;
|
||||
this.distance_y = this.distance_x*Math.abs(this.targetPos.y-this.node.position.y)/Math.abs(this.targetPos.x-this.node.position.x)*dir_y;
|
||||
this.startMovement();
|
||||
// if ( this.targetPos) {
|
||||
// // 计算朝向
|
||||
// let direction = this.targetPos.x > this.node.position.x ? 1 : -1;
|
||||
// // 设置节点缩放来改变朝向
|
||||
// this.node.scale = v3(direction * Math.abs(this.scale), this.scale, 1);
|
||||
// }
|
||||
// let dir_y = ( this.targetPos.y+BoxSet.ATK_Y) > this.node.position.y ? 1 : -1
|
||||
// if( this.targetPos.y+BoxSet.ATK_Y==this.node.position.y){
|
||||
// dir_y=0
|
||||
// }
|
||||
// // 计算这一帧的移动距离
|
||||
// this.distance_x = SkillSet[this.s_uuid].speed*dir_x;
|
||||
// this.distance_y = this.distance_x*Math.abs(this.targetPos.y-this.node.position.y)/Math.abs(this.targetPos.x-this.node.position.x)*dir_y;
|
||||
// this.startMovement();
|
||||
|
||||
// 计算目标角度
|
||||
if (this.targetPos) {
|
||||
const currentPos = this.node.position;
|
||||
// // 计算目标角度
|
||||
// if (this.targetPos) {
|
||||
// const currentPos = this.node.position;
|
||||
|
||||
// 计算角度(弧度)
|
||||
const dx = this.targetPos.x - currentPos.x;
|
||||
const dy = (this.targetPos.y + BoxSet.ATK_Y) - currentPos.y;
|
||||
const angle = Math.atan2(dy, dx);
|
||||
// // 计算角度(弧度)
|
||||
// const dx = this.targetPos.x - currentPos.x;
|
||||
// const dy = (this.targetPos.y + BoxSet.ATK_Y) - currentPos.y;
|
||||
// const angle = Math.atan2(dy, dx);
|
||||
|
||||
// 将弧度转换为角度并设置节点旋转
|
||||
this.angle = angle * 180 / Math.PI;
|
||||
this.node.angle = this.angle; // 移除负号,修正角度方向
|
||||
}
|
||||
// // 将弧度转换为角度并设置节点旋转
|
||||
// this.angle = angle * 180 / Math.PI;
|
||||
// this.node.angle = this.angle; // 移除负号,修正角度方向
|
||||
// }
|
||||
|
||||
// 计算速度分量
|
||||
const radians = this.angle * Math.PI / 180; // 移除负号,使用正确的角度
|
||||
this.distance_x = this.speed * Math.cos(radians);
|
||||
this.distance_y = this.speed * Math.sin(radians);
|
||||
// // 计算速度分量
|
||||
// const radians = this.angle * Math.PI / 180; // 移除负号,使用正确的角度
|
||||
// this.distance_x = this.speed * Math.cos(radians);
|
||||
// this.distance_y = this.speed * Math.sin(radians);
|
||||
|
||||
this.startMovement();
|
||||
// this.startMovement();
|
||||
// console.log("skill start",this.node.parent)
|
||||
}
|
||||
onBeginContact (seCol: Collider2D, oCol: Collider2D) {
|
||||
@@ -114,7 +121,7 @@ export class SkillCom extends CCComp {
|
||||
|
||||
|
||||
private startMovement() {
|
||||
switch(this.animType) {
|
||||
switch(SkillSet[this.s_uuid].AnimType) {
|
||||
case AnimType.parabolic:
|
||||
this.startBezierMove();
|
||||
break;
|
||||
@@ -146,18 +153,18 @@ export class SkillCom extends CCComp {
|
||||
}
|
||||
|
||||
private startBezierMove() {
|
||||
if (!this.targetPos) return;
|
||||
let s_pos = v3(this.startPos.x,this.startPos.y)
|
||||
let c_pos = v3((this.targetPos.x+this.startPos.x)/2,this.startPos.y+150)
|
||||
let e_pos = v3(this.targetPos.x,this.targetPos.y)
|
||||
let time =Math.abs(Math.abs(this.targetPos.x-this.startPos.x)/this.speed)
|
||||
|
||||
// let s_pos = v3(this.startPos.x,this.startPos.y)
|
||||
// let c_pos = v3((this.targetPos.x+this.startPos.x)/2,this.startPos.y+150)
|
||||
// let e_pos = v3(this.targetPos.x,this.targetPos.y)
|
||||
// let time =Math.abs(Math.abs(this.targetPos.x-this.startPos.x)/this.speed)
|
||||
|
||||
// console.log("开始贝塞尔运动=>time:"+time,"s_pos:"+s_pos,"c_pos:"+c_pos,"e_pos:"+e_pos)
|
||||
SkillCom.bezierTo(this.node,time,s_pos,c_pos,e_pos,{
|
||||
onComplete: (target?: object) => {
|
||||
this.is_destroy=true
|
||||
},
|
||||
}).start();
|
||||
// // console.log("开始贝塞尔运动=>time:"+time,"s_pos:"+s_pos,"c_pos:"+c_pos,"e_pos:"+e_pos)
|
||||
// SkillCom.bezierTo(this.node,time,s_pos,c_pos,e_pos,{
|
||||
// onComplete: (target?: object) => {
|
||||
// this.is_destroy=true
|
||||
// },
|
||||
// }).start();
|
||||
}
|
||||
|
||||
private startFixedMove() {
|
||||
@@ -233,7 +240,7 @@ export class SkillCom extends CCComp {
|
||||
update(deltaTime: number) {
|
||||
if(smc.mission.pause) return;
|
||||
this.toDestroy();
|
||||
this.startLinearMove(deltaTime);
|
||||
if(this.animType==AnimType.linear) this.startLinearMove(deltaTime);
|
||||
|
||||
}
|
||||
toDestroy() {
|
||||
|
||||
Reference in New Issue
Block a user