技能移动修改

This commit is contained in:
2024-08-21 14:10:17 +08:00
parent 3f18763730
commit 76a7854e94
15 changed files with 161 additions and 104 deletions

View File

@@ -28,7 +28,7 @@ export class Skill extends ecs.Entity {
this.remove(SkillCom);
super.destroy();
}
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,range:number = 50,scale:number = 1,parent:Node,skill_name:string = "base",atk:number =10) {
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,dis:number = 50,scale:number = 1,parent:Node,skill_name:string = "base",atk:number =10,t_pos:Vec3 = null) {
var path = "game/skills/"+skill_name;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
@@ -36,12 +36,13 @@ export class Skill extends ecs.Entity {
node.setScale(scale,1)
//转换pos为世界坐标
node.setPosition(pos)
var sv = node.getComponent(SkillCom)!;
sv.speed = speed;
sv.range = range;
sv.dis = dis;
sv.scale = scale;
sv.atk = atk;
sv.t_pos = t_pos;
if(scale == 1){
sv.change_collider_group(BoxSet.HERO_SKILL)
}else{

View File

@@ -1,4 +1,4 @@
import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact} from "cc";
import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween} from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { BoxSet } from "../common/config/BoxSet";
@@ -16,9 +16,10 @@ export class SkillCom extends CCComp {
// // this.on(ModuleEvent.Cmd, this.onHandler, this);
// }
speed:number = 200;
range:number = 80;
dis:number = 80;
scale:number = 1;
atk:number = 10;
t_pos:Vec3 = null;
is_destroy:boolean = false;
start() {
this.node.active=true
@@ -27,6 +28,19 @@ export class SkillCom extends CCComp {
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
if(this.t_pos){
tween(this.node).to( 0.5,{ position: new Vec3(0, 10, 0) } ).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.toDestroy()
},
}
).start();
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
switch (selfCollider.group) {
@@ -67,9 +81,9 @@ export class SkillCom extends CCComp {
collider.group = group;
}
update(deltaTime: number) {
this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
this.node.setPosition(v3(this.node.position.x+deltaTime*this.speed*this.scale,this.node.position.y,this.node.position.z))
if(Math.abs(this.node.position.x) > this.range)
// this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
this.move(deltaTime)
if(Math.abs(this.node.position.x) > this.dis)
{
if(this.is_destroy){
return
@@ -81,6 +95,11 @@ export class SkillCom extends CCComp {
}
}
move(dt: number) {
// this.node.setPosition(v3(this.node.position.x+dt*this.speed*this.scale,this.node.position.y,this.node.position.z))
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {