Page 1 of 1

How to get target facing data?

Posted: Wed Oct 25, 2017 8:59 pm
by imB_YipMan
Is it possible to return the facing of a token in a targeting script?
I haven't seen any script that does.

In example i would like to see something like this:

Code: Select all

[Attacker] fires an arrow and hits [TargetName] at a [Angle] degree angle.
[Attacker] successfully bypasses [Targetname]'s shield.  

Re: How to get target facing data?

Posted: Wed Oct 25, 2017 11:02 pm
by Full Bleed
imB_YipMan wrote:Is it possible to return the facing of a token in a targeting script?
I haven't seen any script that does.

In example i would like to see something like this:

Code: Select all

[Attacker] fires an arrow and hits [TargetName] at a [Angle] degree angle.
[Attacker] successfully bypasses [Targetname]'s shield.  
You should be able to work this out by grabbing the token locations, facing, and then working out the math.

Wiki: getTokenFacing()
Wiki: getTokenX()
Wiki: getTokenY()
Category:Mathematical_Function

That said, this would be a luxury feature... most certainly with a degree of precision you don't get on a table. Do you need that sort of precision to resolve this sort of thing? How do you do this when playing on a table?

Re: How to get target facing data?

Posted: Wed Nov 08, 2017 8:59 pm
by imB_YipMan
Full Bleed wrote:
imB_YipMan wrote:Is it possible to return the facing of a token in a targeting script?
I haven't seen any script that does.

In example i would like to see something like this:

Code: Select all

[Attacker] fires an arrow and hits [TargetName] at a [Angle] degree angle.
[Attacker] successfully bypasses [Targetname]'s shield.  
You should be able to work this out by grabbing the token locations, facing, and then working out the math.

Wiki: getTokenFacing()
Wiki: getTokenX()
Wiki: getTokenY()
Category:Mathematical_Function

That said, this would be a luxury feature... most certainly with a degree of precision you don't get on a table. Do you need that sort of precision to resolve this sort of thing? How do you do this when playing on a table?
I am making a turn based version of Mount and blade bannerlord - partially copying the combat system there, with some modifications to make it work in turn based game play.
Once the combat system is done I will add RPG elements mainly from D&D.

The angles are calculated in so far 4 situations:
a) Ambushes
b) When a target is "pinned" by an aggressive opponent
c) When a target is targeting another unit
d) The target is routed or fleeing

The steeper the angle - the lower the chance of the target being able to spot or defend the incoming attack.

If you could help me out on this one I would be extremely thankful!

Re: How to get target facing data?

Posted: Sun Nov 19, 2017 4:54 pm
by imB_YipMan
For those interested in calculating offset between an Attacker and a Defender, you can use this code (Probably better ways to do it, but there is no similar code available as I know)!

Code: Select all

<TARGETTING DATA>


<Get player ID and Facing >
[h:PlayerID = currentToken()]
[h:PlayerFacing = getTokenFacing(PlayerID)]


<Get attacker ID & Relative Offset>
[h: EnemyFacing = getTokenFacing(SelectedTargetID)]

[h,if(EnemyFacing > 0), CODE: {
[h:RelativeAngle = (180-abs(EnemyFacing))*(-1)] 
};{
[h:RelativeAngle = (180-abs(EnemyFacing))] 
}]





[h,if(abs(PlayerFacing - RelativeAngle) < 180), CODE: {  
[EnemyAttackAngle = PlayerFacing - RelativeAngle]
};{

[h,if(abs(PlayerFacing-RelativeAngle) > 0), CODE: {
[EnemyAttackAngle =(180+ (180- abs (PlayerFacing - RelativeAngle)))* (-1) ]
};{
[EnemyAttackAngle = 180- abs (PlayerFacing - RelativeAngle)]
}]

}]
[h:EnemyAttackAngle = abs(EnemyAttackAngle)] 

<hr>
Player facing: [PlayerFacing] <br>
Enemy facing: [EnemyFacing]<br>
Relative angle: [RelativeAngle]<br>
The resulting angle is: [EnemyAttackAngle]<br>