Aim from AimFromWeapon piece

Aim from AimFromWeapon piece

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Aim from AimFromWeapon piece

Post by KDR_11k »

I'm tired of the constant issues the current code that aims from the QueryWeapon piece causes. It makes units that are too close to each other wobble their aim back and forth without ever shooting.

Image

This explains the problem: If the target is close enough to the turret the heading reported by AimWeaponX is off since it reports the angle between the muzzle of the turret and the target, the turret then rotates around its base which changes the angle between the muzzle and the target. The angles in this pic are exaggerated but for the engine there's no difference: If the turret turns past the target before the next aim call happens, the next call will make it turn in the opposite direction which makes it move back to its previous rotation and back and forth. At larger distances the series of headings converges and at some point the turret will point at the target (and usually the difference between two headings will be small enough to let the turret reach them before the next AimWeapon call happens and thus shoot) but at shorter ranges this will mess up. If you've played Kernel Panic's older versions you probably know the trick where you send a bit right into a byte and the byte's aiming code screws up, making it shake back and forth but never shoot. The same can be observed in mods with units that have gunds that stick out, e.g. Gundam's mechs with rifles.

The solution is simple: Do it like OTA and make AimWeapon report the angle between the AimFromWeaponX piece and the target, usually the AimFromWeapon piece will be the turret base and thus not move as the unit is aiming and have enough distance from the target to report the right angle the first time.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

+1

May look into it myself but no promises.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

It's probably just changing one line to poll AimFromWeapon instead of QueryWeapon before calling AimWeapon.
User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Post by Guessmyname »

Bet it isn't
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

I've looked into the code, it already uses AimFromWeapon but only when some variable called useWeaponPosForAim is 0 and it seems to get set based on the reload time or something. If I could get it to compile I could force it to use AimFromWeaponX at all times and see what happens.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Okay, this isn't easy since all weapons use only one varianble for both their aim and firepoint. I'm trying to split that up now.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

Good luck, that bug is quite annoying.

Also, don't forget that while the angle parameters passed to the aiming function must be calculated from the turret center, it's best the direction the shot goes is calculated from the shot initial posiiton, so the firepoint.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

I made a patch that works as far as I have tested, not sure if the variable names I introduced are acceptable, though.
User avatar
clericvash
Posts: 1394
Joined: 05 Oct 2004, 01:05

Post by clericvash »

I hope it works, it is rather annoying!
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Patch is here for anyone who wants to try it.
User avatar
SwiftSpear
Classic Community Lead
Posts: 7287
Joined: 12 Aug 2005, 09:29

Post by SwiftSpear »

Moved to development, since this is now a WIP feature, and not simply a request.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Post by imbaczek »

This patch also helps very short range (i.e. melee with beamlaser) weapons. Very noticable improvement in zaku2melee behaviour. Still not perfect and still working on it, but there's hope.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

The Zaku2melee suffers from having a limited firearc, the code that makes the unit try to get the target in its firearc doesn't work too well at close ranges AFAIK, I had issues with that even for the schoolgirl in the lolimod which is why I don't use a firearc in that.

http://spring.unknown-files.net/file/30 ... provement/

That should improve the unit's behaviour, it gives it a 360° firearc on its weapon1 but it can't use that if it's moving (I wanted to turn the whole unit when it's standing still but currently it seems to only turn the torso, no idea which part(s) I'd have to turn).
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Post by imbaczek »

I used the stock gundam 1.11, hacked some stuff in the engine and here are the results: http://neoteric.pl/~imbaczek/spring/muz ... Border.avi

Still don't know whether this is good or not.
Post Reply

Return to “Engine”