Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitMotionFlying.js
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | UnitMotionFlying.prototype.OnUpdate = function(msg) | ||||
} | } | ||||
// If we're in range of the target then tell people that we've reached it | // If we're in range of the target then tell people that we've reached it | ||||
// (TODO: quantisation breaks this) | // (TODO: quantisation breaks this) | ||||
var distFromTarget = Math.euclidDistance2D(pos.x, pos.z, this.targetX, this.targetZ); | var distFromTarget = Math.euclidDistance2D(pos.x, pos.z, this.targetX, this.targetZ); | ||||
if (!this.reachedTarget && this.targetMinRange <= distFromTarget && distFromTarget <= this.targetMaxRange) | if (!this.reachedTarget && this.targetMinRange <= distFromTarget && distFromTarget <= this.targetMaxRange) | ||||
{ | { | ||||
this.reachedTarget = true; | this.reachedTarget = true; | ||||
Engine.PostMessage(this.entity, MT_MotionChanged, { "starting": false, "error": false }); | Engine.PostMessage(this.entity, MT_MotionUpdate, { "updateString": "likelySuccess" }); | ||||
} | } | ||||
// If we're facing away from the target, and are still fairly close to it, | // If we're facing away from the target, and are still fairly close to it, | ||||
// then carry on going straight so we overshoot in a straight line | // then carry on going straight so we overshoot in a straight line | ||||
var isBehindTarget = ((this.targetX - pos.x) * Math.sin(angle) + (this.targetZ - pos.z) * Math.cos(angle) < 0); | var isBehindTarget = ((this.targetX - pos.x) * Math.sin(angle) + (this.targetZ - pos.z) * Math.cos(angle) < 0); | ||||
// Overshoot the target: carry on straight | // Overshoot the target: carry on straight | ||||
if (isBehindTarget && distFromTarget < this.template.MaxSpeed * this.template.OvershootTime) | if (isBehindTarget && distFromTarget < this.template.MaxSpeed * this.template.OvershootTime) | ||||
canTurn = false; | canTurn = false; | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | UnitMotionFlying.prototype.SetSpeedMultiplier = function() | ||||
// ignore this, the speed is always the walk speed | // ignore this, the speed is always the walk speed | ||||
}; | }; | ||||
UnitMotionFlying.prototype.GetRunMultiplier = function() | UnitMotionFlying.prototype.GetRunMultiplier = function() | ||||
{ | { | ||||
return 1; | return 1; | ||||
}; | }; | ||||
UnitMotionFlying.prototype.IsMoveRequested = function() | |||||
{ | |||||
return this.hasTarget; | |||||
} | |||||
UnitMotionFlying.prototype.GetCurrentSpeed = function() | UnitMotionFlying.prototype.GetCurrentSpeed = function() | ||||
{ | { | ||||
return this.speed; | return this.speed; | ||||
}; | }; | ||||
UnitMotionFlying.prototype.GetSpeedMultiplier = function() | UnitMotionFlying.prototype.GetSpeedMultiplier = function() | ||||
{ | { | ||||
return this.GetCurrentSpeed() / this.GetWalkSpeed(); | return this.GetCurrentSpeed() / this.GetWalkSpeed(); | ||||
Show All 35 Lines |
Wildfire Games · Phabricator