|
@@ -1,11 +1,9 @@
|
|
|
-import { _decorator, Vec3,Node, geometry, PhysicsSystem, PhysicsRayResult, native} from 'cc';
|
|
|
-import { Gun1 } from './Gun1';
|
|
|
+import { _decorator, Vec3,Node, geometry, PhysicsSystem, PhysicsRayResult} from 'cc';
|
|
|
import { Game } from '../../game/Game';
|
|
|
import { GunBase } from '../base/GunBase';
|
|
|
import { BulletBase } from '../base/BulletBase';
|
|
|
import { Enemy, EPartType } from '../../game/Enemy';
|
|
|
import { PoolManager } from '../../core/manager/PoolManager';
|
|
|
-import MsgHints from '../../utils/MsgHints';
|
|
|
import { Sundries } from '../../game/Sundries';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
@@ -16,6 +14,8 @@ export class Bullet1 extends BulletBase {
|
|
|
private isRemoveDead: boolean = false;
|
|
|
//射击方向的位置
|
|
|
private vector: Vec3 = null;
|
|
|
+ //计算子弹停留时间
|
|
|
+ private time: number = 0.6;
|
|
|
|
|
|
/**
|
|
|
* 初始化一个子弹
|
|
@@ -36,10 +36,10 @@ export class Bullet1 extends BulletBase {
|
|
|
* @param v 射向的方向
|
|
|
*/
|
|
|
public setBulletVector(v: Vec3){
|
|
|
+ this.time = this.getBulletTime();
|
|
|
const bulletSpeed = this.gunBase.data.bulletSpeed / 3;
|
|
|
this.vector = v.clone().multiplyScalar(bulletSpeed);
|
|
|
this.node.forward = v;
|
|
|
- this.rayPreCheck(bulletSpeed / 60);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -65,31 +65,33 @@ export class Bullet1 extends BulletBase {
|
|
|
if(this.vector) {
|
|
|
const moveDelta = this.vector.clone().multiplyScalar(deltaTime);
|
|
|
this.node.worldPosition = this.node.worldPosition.add(moveDelta);
|
|
|
- this.rayPreCheck(moveDelta.length());
|
|
|
+ //开始检测射击
|
|
|
+ this.scheduleOnce(this.rayPreCheck,this.time);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 检测射击
|
|
|
* @param b
|
|
|
* @param len 检测
|
|
|
*/
|
|
|
- private rayPreCheck(len: number) {
|
|
|
- const p = this.node.worldPosition;
|
|
|
- const ray = geometry.Ray.create(p.x, p.y, p.z, this.vector.x, this.vector.y, this.vector.z);
|
|
|
- const phy:PhysicsSystem = PhysicsSystem.instance;
|
|
|
- const isHit = phy.raycast(ray, 0xffffff, len);
|
|
|
- if (isHit && phy.raycastResults.length > 0) {
|
|
|
+ private rayPreCheck() {
|
|
|
+ let screenPos: Vec3 = Game.I.player.shootUI.getScreenCenterPos();
|
|
|
+ const r = geometry.Ray.create();
|
|
|
+ Game.I.camera.screenPointToRay(screenPos.x, screenPos.y, r);
|
|
|
+ const hasHit = PhysicsSystem.instance.raycast(r, 0xffffffff, 100000, true);
|
|
|
+ const raycastResults:PhysicsRayResult[] = PhysicsSystem.instance.raycastResults;
|
|
|
+ if(hasHit && raycastResults.length > 0){
|
|
|
//先查找 要检测的物体 对象上带args参数的就是优先检测的
|
|
|
let targetResult: PhysicsRayResult | null = null;
|
|
|
- for (const result of phy.raycastResults) {
|
|
|
+ for (const result of raycastResults) {
|
|
|
if (result.collider["args"]) {
|
|
|
targetResult = result;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- targetResult = targetResult ?? phy.raycastResults[0];
|
|
|
- //targetResult.collider.getComponent(RigidBody).applyForce(this.vector, targetResult.hitPoint);
|
|
|
+ targetResult = targetResult ?? raycastResults[0];
|
|
|
this.addHitImpact(targetResult);
|
|
|
const args:any = targetResult.collider["args"];
|
|
|
if(args){
|