mirror of
https://github.com/Sheldan/canvas.git
synced 2026-04-05 01:02:57 +00:00
survivors: fixing homing projectiles behaving correctly after losing the target
This commit is contained in:
@@ -54,8 +54,12 @@ export class Vector {
|
|||||||
return (this._x * vector._x + this._y * vector._y) / Math.pow(vector.vecLength(), 2);
|
return (this._x * vector._x + this._y * vector._y) / Math.pow(vector.vecLength(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dotProduct2(vector: Vector): number {
|
||||||
|
return (this._x * vector._x + this._y * vector._y)
|
||||||
|
}
|
||||||
|
|
||||||
angleTo(vector: Vector): number {
|
angleTo(vector: Vector): number {
|
||||||
return Math.acos(this.dotProduct(vector))
|
return Math.acos(this.dotProduct2(vector) / (this.vecLength() * vector.vecLength()))
|
||||||
}
|
}
|
||||||
|
|
||||||
get x(): number {
|
get x(): number {
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ docReady(function () {
|
|||||||
}, 10_000)
|
}, 10_000)
|
||||||
|
|
||||||
player.addWeapon(Pistol.generatePistol(world))
|
player.addWeapon(Pistol.generatePistol(world))
|
||||||
player.addWeapon(HomingPistol.generatePistol(world))
|
player.addWeapon(HomingPistol.generateHomingPistol(world))
|
||||||
hud = new HUD(world);
|
hud = new HUD(world);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ export class HomingProjectile extends Projectile {
|
|||||||
if(target.dead()) {
|
if(target.dead()) {
|
||||||
let closestTargetTo = this.world.getClosestTargetTo(this.position)
|
let closestTargetTo = this.world.getClosestTargetTo(this.position)
|
||||||
|
|
||||||
let newTargetDirection = Vector.createVector(this.target.getPosition(), this.position)
|
let oldTargetDirection = Vector.createVector(this.target.getPosition(), this.position)
|
||||||
let justMovedDirection = Vector.createVector(this.position, this.lastPosition).normalize()
|
let justMovedDirection = Vector.createVector(this.position, this.lastPosition).normalize()
|
||||||
let olderMovedDirection: Vector;
|
let olderMovedDirection: Vector;
|
||||||
if(this.secondToLastPosition !== undefined) {
|
if(this.secondToLastPosition !== undefined) {
|
||||||
@@ -155,8 +155,8 @@ export class HomingProjectile extends Projectile {
|
|||||||
if (closestTargetTo !== undefined && closestTargetTo[1] !== undefined) {
|
if (closestTargetTo !== undefined && closestTargetTo[1] !== undefined) {
|
||||||
let newTargetPosition = closestTargetTo[1]!.getPosition();
|
let newTargetPosition = closestTargetTo[1]!.getPosition();
|
||||||
let newDir = Vector.createVector(newTargetPosition, this.position)
|
let newDir = Vector.createVector(newTargetPosition, this.position)
|
||||||
let newDirAngle = newDir.angleTo(newTargetDirection);
|
let newDirAngle = newDir.angleTo(oldTargetDirection);
|
||||||
if(Math.abs(newDirAngle) >= toRad(150)) {
|
if(Math.abs(newDirAngle) <= toRad(30)) {
|
||||||
this.target = closestTargetTo[1]!;
|
this.target = closestTargetTo[1]!;
|
||||||
} else {
|
} else {
|
||||||
if(pointOnLineWithinLine(this.target.getPosition(), this.lastPosition, this.position)) {
|
if(pointOnLineWithinLine(this.target.getPosition(), this.lastPosition, this.position)) {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export class HomingPistol extends RangeWeapon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static generatePistol(world: World, offset?: Vector) {
|
static generateHomingPistol(world: World, offset?: Vector) {
|
||||||
if(!offset) {
|
if(!offset) {
|
||||||
offset = new Vector(5, 5)
|
offset = new Vector(5, 5)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user