This commit is contained in:
pan
2024-08-27 13:03:18 +08:00
parent c598e8964a
commit 45a230db33
4 changed files with 82 additions and 31 deletions

View File

@@ -105,8 +105,8 @@
},
"_lscale": {
"__type__": "cc.Vec3",
"x": -0.6,
"y": 0.6,
"x": -0.5,
"y": 0.5,
"z": 1
},
"_mobility": 0,

View File

@@ -105,8 +105,8 @@
},
"_lscale": {
"__type__": "cc.Vec3",
"x": -1,
"y": 1,
"x": -0.5,
"y": 0.5,
"z": 1
},
"_mobility": 0,

View File

@@ -62,7 +62,9 @@ export class CSkillComp extends CCComp {
m_pos = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
}
t_pos = v3(m_pos.x-this.node.position.x,m_pos.y-this.node.position.y) // 目标增量
// console.log("m_pos",this.node.position,m_pos);
// console.log("m_pos",m_pos);
// console.log("pos",this.node.position);
// console.log("t_pos",t_pos);
let dx=m_pos.x-this.node.position.x
let dy=m_pos.y-this.node.position.y
let dir=v3(dx,dy,0)

View File

@@ -30,7 +30,9 @@ export class SkillCom extends CCComp {
type:number = 1;
time:Timer = new Timer(0.01);
start() {
// console.log("skill start position :",this.node.position)
// console.log("skill start parent :",this.node.parent)
// console.log("skill start t position :",this.t_pos)
this.node.active=true
this.node.angle = this.angle;
let collider = this.getComponent(Collider2D);
@@ -44,31 +46,43 @@ export class SkillCom extends CCComp {
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
if(this.t_pos){
//通过欧拉角 延长 目标点 增量
// this.t_pos.x=Math.cos(this.angle * Math.PI / 180) * this.dis;
// this.t_pos.y=Math.sin(this.angle * Math.PI / 180) * this.dis;
tween(this.node).to( 0.5,{ angle:this.angle,position: this.t_pos},
{
onUpdate: (target: Vec3, ratio: number) => { // onUpdate 接受当前缓动的进度
// 将缓动系统计算出的结果赋予 node 的位置
},
onComplete: (target?: object) => {
this.is_destroy=true
},
}
).start();
this.x_speed=this.t_pos.x;
this.y_speed=this.t_pos.y;
}else{
tween(this.node).to( this.dis/this.speed,
{ position: new Vec3(this.node.position.x+this.scale*this.dis,this.node.position.y) },
{
onComplete: (target?: object) => {
this.is_destroy=true
},
let s_pos = v3(this.node.position.x,this.node.position.y)
let c_pos = v3(this.node.position.x,this.node.position.y+200)
let e_pos = v3(this.node.position.x+100*this.scale,BoxSet.GAME_LINE-50)
SkillCom.bezierTo(this.node,2,s_pos,c_pos,e_pos,{onUpdate: (target: Vec3, ratio: number) => {
}
).start();
}).start();
}
// if(this.t_pos){
// //通过欧拉角 延长 目标点 增量
// // this.t_pos.x=Math.cos(this.angle * Math.PI / 180) * this.dis;
// // this.t_pos.y=Math.sin(this.angle * Math.PI / 180) * this.dis;
// tween(this.node).to( 0.5,{ angle:this.angle,position: this.t_pos},
// {
// onUpdate: (target: Vec3, ratio: number) => { // onUpdate 接受当前缓动的进度
// // 将缓动系统计算出的结果赋予 node 的位置
// },
// onComplete: (target?: object) => {
// this.is_destroy=true
// },
// }
// ).start();
// }else{
// tween(this.node).to( this.dis/this.speed,
// { position: new Vec3(this.node.position.x+this.scale*this.dis,this.node.position.y) },
// {
// onComplete: (target?: object) => {
// this.is_destroy=true
// },
// }
// ).start();
// }
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(otherCollider.group != selfCollider.group&&otherCollider.tag !=BoxSet.ATK_RANGE&&otherCollider.tag !=BoxSet.SKILL_TAG){
@@ -109,10 +123,25 @@ export class SkillCom extends CCComp {
// this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
// this.move(deltaTime)
this.toDestroy()
// if(this.t_pos){
// this.t_move(deltaTime)
// }else{
// this.line_move(deltaTime)
// }
if (this.node.position.x > 400||this.node.position.x < -400||this.node.position.y > 1000||this.node.position.y < BoxSet.GAME_LINE) {
this.is_destroy=true
}
move(dt: number) {
// this.node.setPosition(v3(this.node.position.x+dt*this.x_speed*this.scale,this.node.position.y+this.y_speed,this.node.position.z))
}
t_move(dt: number){
this.node.setPosition(v3(this.node.position.x+this.x_speed*dt*this.scale,this.node.position.y+this.y_speed*dt))
}
line_move(dt: number) {
this.node.setPosition(v3(this.node.position.x+dt*this.speed*this.scale,this.node.position.y))
}
bezier(t:number){
}
toDestroy() {
if(this.is_destroy){
@@ -125,4 +154,24 @@ export class SkillCom extends CCComp {
this.is_destroy=false
this.node.destroy();
}
public static bezierTo(target: any, duration: number, c1: Vec3, c2: Vec3, to: Vec3, opts: any) {
opts = opts || Object.create(null);
/*
* @desc 二阶贝塞尔
* @param {number} t 当前百分比
* @param {} p1 起点坐标
* @param {} cp 控制点
* @param {} p2 终点坐标
* @returns {any}
*/
let twoBezier = (t:number, p1: Vec3, cp: Vec3, p2: Vec3) => {
let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
return v3(x, y, 0);
};
opts.onUpdate = (arg: Vec3, ratio: number) => {
target.position = twoBezier(ratio, c1, c2, to);
};
return tween(target).to(duration, {}, opts);
}
}