DoomImp to throw fireballs in an arc that lands on target?
Posted: Fri Sep 01, 2017 12:34 pm
Hi, all. I have—to a distressing lack of avail—tried to make DoomImps (herein referred to as just imps) throw their DoomImpBalls (herein referred to as just fireballs) in an arc that lands on the player, like in Doom 4.
OK, fireballs now have Gravity set to 0.05 and the NOGRAVITY flag removed. Cool, that's them done (except I need to stop their gravity in their Death state; falling poofs of fire look pretty weird.) That's all great, but I want the imps to throw their fireballs with the right angle to hit the target (if not possible then not at all.)
So for the imps, I have this:
Idiotically, I reverted from all attempts back to a hardcoded angle of 1 degree, but there's a placeholder function (not assuming that the answer will be so simple) where I don't know how to do something-- so not the 1 degree thing. Instead, the actor's distance on the XY plane (X as far as the 2D calculations are concerned,) the Z distance, the gravity that fireballs are subjected to and their speed (which is different with FastMonsters, so... gotta think about that one.)
My previous attempts, though, involved using GetDistance(false) (for the XY plane) and using it as variable x (we've got a rotated 2D representation of the plane on which the imp and the target lie) and then doing

to get the y variable (so done because how do i get the relative Z offset of the target in a cleaner way?), doing this (g = Gravity, v = Speed or FastSpeed)

(aborting the whole missile attack if the expression being square-rooted is negative, because that means that the ball cannot hit the target)
from wikipedia. Also, the plus-or-minus sign can be whichever, both get the right angle apparently
...yeah, that... and using the theta on the left to get the angle required. but... i can't really describe how it all went wrong now. In future I won't destroy previous attempts.
I've tried A_ThrowGrenade("DoomImpBall"), but it's not always accurate, especially if I'm not level with the imp.
So yeah, I really need some help coming up with an approach to this
EDIT: the post was slightly unfinished
EDIT2: got fastmissile and missile swapped, derp
OK, fireballs now have Gravity set to 0.05 and the NOGRAVITY flag removed. Cool, that's them done (except I need to stop their gravity in their Death state; falling poofs of fire look pretty weird.) That's all great, but I want the imps to throw their fireballs with the right angle to hit the target (if not possible then not at all.)
So for the imps, I have this:
Code: Select all
ACTOR _DoomImp: DoomImp replaces DoomImp
{
States {
Melee:
TROO EF 8 A_FaceTarget
TROO G 6 A_CustomMeleeAttack(3 * random(1, 10), "imp/melee")
Goto See
Missile:
TROO E 0 A_JumpIf(FastMonstersIsTrue, "FastMissile")
TROO EF 8 A_FaceTarget
TROO G 6 A_SpawnProjectile("DoomImpBall", 32, 0, 0, CMF_AIMDIRECTION, GetAppropriateAngleOrJumpIfOutOfRange("See", AAPTR_TARGET, 0.05, 10)) // Presumably CMF_AIMDIRECTION is the right flag to use? I couldn't _really_ tell.
Goto See
FastMissile:
TROO EF 8 A_FaceTarget
TROO G 6 A_SpawnProjectile("DoomImpBall", 32, 0, 0, CMF_AIMDIRECTION, GetAppropriateAngleOrJumpIfOutOfRange("See", AAPTR_TARGET, 0.05, 20))
}
}
My previous attempts, though, involved using GetDistance(false) (for the XY plane) and using it as variable x (we've got a rotated 2D representation of the plane on which the imp and the target lie) and then doing

to get the y variable (so done because how do i get the relative Z offset of the target in a cleaner way?), doing this (g = Gravity, v = Speed or FastSpeed)

(aborting the whole missile attack if the expression being square-rooted is negative, because that means that the ball cannot hit the target)
from wikipedia. Also, the plus-or-minus sign can be whichever, both get the right angle apparently
...yeah, that... and using the theta on the left to get the angle required. but... i can't really describe how it all went wrong now. In future I won't destroy previous attempts.
I've tried A_ThrowGrenade("DoomImpBall"), but it's not always accurate, especially if I'm not level with the imp.
So yeah, I really need some help coming up with an approach to this

EDIT: the post was slightly unfinished
EDIT2: got fastmissile and missile swapped, derp