|
@@ -1,5 +1,5 @@
|
|
-import { Role } from "./Role";
|
|
|
|
-import GameDefined, { CheckType } from "../game_module/GameDefined";
|
|
|
|
|
|
+
|
|
|
|
+import GameDefined, { CheckType, BulletType } from "../game_module/GameDefined";
|
|
import Vector3 = Laya.Vector3;
|
|
import Vector3 = Laya.Vector3;
|
|
import Ray = Laya.Ray;
|
|
import Ray = Laya.Ray;
|
|
import HitResult = Laya.HitResult;
|
|
import HitResult = Laya.HitResult;
|
|
@@ -8,7 +8,9 @@ import BulletController from "./BulletController";
|
|
import Sprite3D = Laya.Sprite3D;
|
|
import Sprite3D = Laya.Sprite3D;
|
|
import Transform3D = Laya.Transform3D;
|
|
import Transform3D = Laya.Transform3D;
|
|
import Game_Tool from "../game_tool/Game_Tool";
|
|
import Game_Tool from "../game_tool/Game_Tool";
|
|
-export class Bullet extends Laya.Script {
|
|
|
|
|
|
+import { EventManager } from "../game_module/EventManager";
|
|
|
|
+import { Role } from "./Role";
|
|
|
|
+export class Bullet extends Laya.Script3D {
|
|
constructor() {
|
|
constructor() {
|
|
super();
|
|
super();
|
|
}
|
|
}
|
|
@@ -17,8 +19,8 @@ export class Bullet extends Laya.Script {
|
|
private self: Sprite3D;
|
|
private self: Sprite3D;
|
|
onAwake() {
|
|
onAwake() {
|
|
this.self = this.owner as Sprite3D;
|
|
this.self = this.owner as Sprite3D;
|
|
- this.forw = new Vector3(0, 0, 0);
|
|
|
|
this._transform = this.self.transform;
|
|
this._transform = this.self.transform;
|
|
|
|
+ this.forw = new Vector3(0, 0, 0);
|
|
this._corss = new Vector3(0, 0, 0);
|
|
this._corss = new Vector3(0, 0, 0);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -28,29 +30,33 @@ export class Bullet extends Laya.Script {
|
|
private go: Sprite3D;
|
|
private go: Sprite3D;
|
|
private goS: Bullet;
|
|
private goS: Bullet;
|
|
private _corss: Vector3;
|
|
private _corss: Vector3;
|
|
- CreateRay(pos: Vector3, _rotation) {
|
|
|
|
|
|
+ CreateRay(pos: Vector3, _rotation, _type?) {
|
|
if (!this.go) {
|
|
if (!this.go) {
|
|
- this.go = BulletController.Instance.CreateBullet();
|
|
|
|
|
|
+
|
|
|
|
+ switch (_type) {
|
|
|
|
+ case BulletType.BulletG:
|
|
|
|
+ this.go = BulletController.Instance.CreateBullet(GameDefined.poolName.bulletG);
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case BulletType.BulletR:
|
|
|
|
+ this.go = BulletController.Instance.CreateBullet(GameDefined.poolName.BulletR);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
var gs = this.go.getComponent(Bullet);
|
|
var gs = this.go.getComponent(Bullet);
|
|
if (!gs) this.goS = this.go.addComponent(Bullet);
|
|
if (!gs) this.goS = this.go.addComponent(Bullet);
|
|
} else {
|
|
} else {
|
|
this.go.active = true;
|
|
this.go.active = true;
|
|
}
|
|
}
|
|
this.go.transform.position = pos.clone();
|
|
this.go.transform.position = pos.clone();
|
|
- this.go.transform.rotationEuler = _rotation;
|
|
|
|
- // this._transform.getForward(this.forw);
|
|
|
|
|
|
+ this.go.transform.rotationEuler = _rotation;
|
|
|
|
+ this.go.transform.rotate = _rotation;
|
|
this.go.transform.getForward(this.forw);
|
|
this.go.transform.getForward(this.forw);
|
|
this.forw = new Vector3(-this.forw.x, -this.forw.y, -this.forw.z);
|
|
this.forw = new Vector3(-this.forw.x, -this.forw.y, -this.forw.z);
|
|
- var temp=this.forw.clone();
|
|
|
|
|
|
+ var temp = this.forw.clone();
|
|
Vector3.normalize(temp, temp);
|
|
Vector3.normalize(temp, temp);
|
|
- // this.forw = new Vector3(this.forW.x * this.speed, this.forW.y * this.speed, this.forW.z * this.speed);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // var temp = new Vector3(-this.forw.x * 0.01, -this.forw.y * 0.01, -this.forw.z * 0.01);
|
|
|
|
-
|
|
|
|
- pos.x = pos.x + temp.x*0.01;
|
|
|
|
- pos.y = pos.y + temp.y*0.01;
|
|
|
|
- pos.z = pos.z + temp.z*0.01;
|
|
|
|
|
|
+ pos.x = pos.x + temp.x * 0.01;
|
|
|
|
+ pos.y = pos.y + temp.y * 0.01;
|
|
|
|
+ pos.z = pos.z + temp.z * 0.01;
|
|
|
|
|
|
if (!this._ray) {
|
|
if (!this._ray) {
|
|
this._ray = new Ray(pos, this.forw);
|
|
this._ray = new Ray(pos, this.forw);
|
|
@@ -60,35 +66,84 @@ export class Bullet extends Laya.Script {
|
|
this._ray.direction = this.forw;
|
|
this._ray.direction = this.forw;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
var isS = GameSceneController.Instance.game_scene.physicsSimulation.rayCast(this._ray, this._hit);
|
|
var isS = GameSceneController.Instance.game_scene.physicsSimulation.rayCast(this._ray, this._hit);
|
|
if (isS) {
|
|
if (isS) {
|
|
var poi = this._hit.point;
|
|
var poi = this._hit.point;
|
|
var dis = Vector3.distance(pos, poi);
|
|
var dis = Vector3.distance(pos, poi);
|
|
this.go.transform.localScaleZ = dis;
|
|
this.go.transform.localScaleZ = dis;
|
|
var other = this._hit.collider.owner as Sprite3D;
|
|
var other = this._hit.collider.owner as Sprite3D;
|
|
- if (other.layer == GameDefined.player_layer) {
|
|
|
|
|
|
+ if (other.layer == GameDefined.player_layer || other.layer == GameDefined.moster_layer) {
|
|
|
|
+ this.tempPos = pos;
|
|
|
|
+ this.tempRotation = _rotation;
|
|
|
|
+ this.SetTar(other);
|
|
this.goS.SetNextNotActive();
|
|
this.goS.SetNextNotActive();
|
|
} else {
|
|
} else {
|
|
|
|
+ this.RemoveTar();
|
|
var nor = this._hit.normal;
|
|
var nor = this._hit.normal;
|
|
- console.log(nor);
|
|
|
|
|
|
+ nor.x = Math.abs(nor.x) < 0.001 ? 0 : nor.x;
|
|
|
|
+ nor.y = Math.abs(nor.y) < 0.001 ? 0 : nor.y;
|
|
|
|
+ nor.z = Math.abs(nor.z) < 0.001 ? 0 : nor.z;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
Vector3.cross(this.forw, nor, this._corss);//大于0在左方 小于0在右方
|
|
Vector3.cross(this.forw, nor, this._corss);//大于0在左方 小于0在右方
|
|
|
|
+
|
|
|
|
+
|
|
var a = Game_Tool.getReflectAng(this.forw);
|
|
var a = Game_Tool.getReflectAng(this.forw);
|
|
- var ang = this._transform.rotationEuler.clone();
|
|
|
|
|
|
+ // Laya.Quaternion.
|
|
|
|
+ var ang = this.go._transform.rotationEuler.clone();
|
|
this._corss.y >= 0 ? ang.y = ang.y + 2 * a : ang.y = ang.y - 2 * a;
|
|
this._corss.y >= 0 ? ang.y = ang.y + 2 * a : ang.y = ang.y - 2 * a;
|
|
- this.goS.CreateRay(poi, ang);
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ // var ab=new Laya.Quaternion();
|
|
|
|
+ // Laya.Quaternion.createFromAxisAngle(this.forw,-a,ab)
|
|
|
|
+ // this.goS.CreateRay(poi, ab, BulletType.BulletG);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ this.goS.CreateRay(poi, ang, _type);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
|
|
+ this.RemoveTar();
|
|
this.go.transform.localScaleZ = 50;
|
|
this.go.transform.localScaleZ = 50;
|
|
this.goS.SetNextNotActive();
|
|
this.goS.SetNextNotActive();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public SetNextNotActive() {
|
|
|
|
|
|
+ SetNextNotActive() {
|
|
if (this.go) {
|
|
if (this.go) {
|
|
this.go.active = false;
|
|
this.go.active = false;
|
|
if (this.goS) this.goS.SetNextNotActive();
|
|
if (this.goS) this.goS.SetNextNotActive();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private HitTar: Sprite3D;
|
|
|
|
+ private RemoveTar() {
|
|
|
|
+ if (this.HitTar) {
|
|
|
|
+ this.HitTar = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private SetTar(tar) {
|
|
|
|
+ this.HitTar = tar;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private tempPos: Vector3;
|
|
|
|
+ private tempRotation: any;
|
|
|
|
+ private Hit() {
|
|
|
|
+ if (this.HitTar) {
|
|
|
|
+ if (this.HitTar.layer == GameDefined.player_layer || this.HitTar.layer == GameDefined.moster_layer) {
|
|
|
|
+ var r = this.HitTar.getComponent(Role) as Role;
|
|
|
|
+ r.HitEd();
|
|
|
|
+ this.CreateRay(this.tempPos, this.tempRotation);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ onEnable() {
|
|
|
|
+ EventManager.on(GameDefined.HitEvent, this, this.Hit);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ onDisable() {
|
|
|
|
+ EventManager.off(GameDefined.HitEvent, this, this.Hit);
|
|
|
|
+ }
|
|
}
|
|
}
|