Questions about AbilityShoot
Closed this issue · 7 comments
Hi,
I am using the AbilityShoot in a top_down configurated project. At first this wouldn't work because it turns out that the function isInsideLevel() inside the activateComplete() in AbilityShoot is returning false. That makes the activatComplete not spawn anything. The docs on isInsideLevel state:
if you are having issues with this method, it is most likely because
a) your game has pathfinding disabled, and/or
b) your level does not have a continuous border of solid tiles in the collision map
My project has neither; my level is walled off (on those sections there is a collision layer) but with open sections where enemies enter the level from the outside and on those open sections there is no collision layer. I therefore decided to skip this check and this seems to work. I still wonder though, if there is another way to solve this use-case? Will the disabling of that check get me into trouble somewhere (possibly my next question)?
Furthermore, I use that Abilityshoot with Input points for a shoot-where-I-click style. However, although my projectiles are spot on when I aim at 0/90/180/270 degrees from point of origin (player), they miss the point where I click with a considerable amount when I aim 45/135/225/315 degrees. The amount of 'miss-offset' seems to interpolate linear between those angles. Any ideas what could be causing this?
Hi @rhmvandelisdonk!
The isInsideLevel
method is a bit strange, as I originally set it up to only check when the shoot ability was used to spawn the projectile at a target. For ex: you'd click to create something, and you probably don't want to allow creation of entities outside the level. However, I should probably remove it from the shoot ability at this point. Thanks for pointing this out!
The problem with the angle I think stems from the way the normal is used. This is probably causing inaccuracy with shooting at angles that are not axis aligned. You can try changing the code starting here: https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abilities/ability-shoot.js#L298
Also I think there might be a typo here: https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abilities/ability-shoot.js#L334
I'm going to push a few changes up to the dev branch, can you see if they work for you?
The removal of the inInsideLevel
check and the other changes work for me (regarding the ability to actually shoot). No solution for the angle accuracy yet, I will look into that issue later.
I have found a solution that works for me. On line https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abilities/ability-shoot.js#L264 I cannot figure out why the normalized vector is multiplied by half the size of the shooting/target entity. As far as I can see the original vector is already calculated using the center of the shooting/target enitity, before it is normalized. When I change those lines (264&265) to:
offsetX = (diffX / length);
offsetY = (diffY / length);
my shots are spot on. What do you think?
Yup, that looks correct. I just now noticed that offset is halfed before it is used to calculate the normal, which would cause problems. I'll push up your fix, thanks for finding this!
Alright, slightly different fix than what you proposed to preserve the offsets. Otherwise it should be accurate, can you give it a test (dev branch)?
Sorry for my late reaction, I was on holiday for a while. I have tested the latest dev branch and it works, thanks!