enemyPosition = enemy1_.transform.position-barel_.transform.position;
enemyDistance = Vector3.Distance(enemy1_.transform.position, transform.position);
enemyVelocity = enemy1_.rigidbody.velocity.magnitude;
distance_ = enemyPosition + enemy1_.transform.forward * enemyDistance * 0.13f * enemyVelocity ;
invertedDistance = (30-distance_.magnitude)/30);
barel_.localRotation = Quaternion.Euler(new Vector3(70.0f+(20.0f*invertedDistance , 0, 0));
dirA = transform.forward - Vector3.Project (transform.forward, Vector3.up);
dirB = (target.position - transform.position)*Time.deltaTime - Vector3.Project ((target.position - transform.position), Vector3.up);
angle = Vector3.Angle (dirA, dirB);
rotationAngle = angle * (Vector3.Dot (Vector3.up, Vector3.Cross (dirA, dirB)) < 0 ? -1 : 1);
rigidbody.angularVelocity = (Vector3.up * rotationAngle * 0.1f);
Statistics: Posted by ozonex — 29 Jul 2012, 16:00
local vax, vay, vaz = self:GetVelocity()
local tempa = self:GetPosition()
local tempb = ent:GetPosition()
local pa = VDiff(tempb, tempa)
local vb = ent:GetBlueprint().Air.MaxAirspeed / 10
local a = (math.pow(vax,2) + math.pow(vaz,2) - math.pow(vb,2))
local b = ( 2 * pa.x * vax + 2 * pa.x * vax)
local c = (math.pow(pa.x,2) +math.pow(pa.z, 2))
discriminant = math.pow(b,2) - (4 * a * c)
if discriminant < 0 then
IssueClearCommands({ent})
elseif discriminant == 0 then
t = (-b - sqrt(discriminant)) / (2*a)
tempa.x = tempa.x + (vax * t)
tempa.y = tempa.y
tempa.z = tempa.z + (vaz * t)
IssueClearCommands({ent})
IssueMove({ent}, tempa)
else
local t1 = (-b - math.sqrt(discriminant)) / (2*a)
local t2 = (-b + math.sqrt(discriminant)) / (2*a)
local t
if t1 < t2 and t1 > 0 then
t = t1
else
t = t2
end
tempa.x = tempa.x + (vax * t)
tempa.y = tempa.y
tempa.z = tempa.z + (vaz * t)
IssueClearCommands({ent})
IssueMove({ent}, tempa)
end
end
Statistics: Posted by Ze_PilOt — 28 Jul 2012, 16:00
Statistics: Posted by uberge3k — 28 Jul 2012, 14:50
Statistics: Posted by Ze_PilOt — 24 Jul 2012, 12:57
Statistics: Posted by Ze_PilOt — 24 Jul 2012, 12:40
Statistics: Posted by Plasma_Wolf — 24 Jul 2012, 12:33
Statistics: Posted by VoiceofReason — 24 Jul 2012, 12:28
Statistics: Posted by Ze_PilOt — 24 Jul 2012, 12:21
| pa + va * t | = t * vb
(pa.x + va.x * t) ^ 2 + (pa.y + va.y * t) ^ 2 = (t * vb) ^ 2
(pa.x ^ 2 + pa.y ^ 2) + ( 2 * pa.x * va.x + 2 * pa.x * va.x) * t + (va.x^2 + va.y^2 - vb^2) * t^2 = 0
ax^2 + bx +c = 0
x = (-b +- sqrt(b^2 - 4ac)) / 2a.
a = (va.x^2 + va.y^2 - vb^2)
b = ( 2 * pa.x * va.x + 2 * pa.x * va.x)
c = (pa.x ^ 2 + pa.y ^ 2)
a = (5^2 + 0^2 - 10^2) = (25 - 100) = -75.
b = ( 2 * -5 * -5 + 2 * -5 * 0) = ( 50 + 0) = 50.
c = (-5^2 + 10^2) = 25 + 100 = 125.
A = (-50 -+ sqrt(50^2 -4*-75*125)
A = -50 +- 200
B = -150
tA = (-50+200) / -150 = 1.
tB = (-50-200) / -150 = 1.666.
Statistics: Posted by Ze_PilOt — 24 Jul 2012, 11:57