Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: marvoc on May 02, 2019, 10:01:08 AM

Title: attack range (circle) - use only part of it [SOLVED]
Post by: marvoc on May 02, 2019, 10:01:08 AM
Hi again ;)
Im trying to resolve this problem:
I have an enemy (V1) and player (V2) vectors. I subtract them and get that line between. Then Im using "Get Vector Length" to get its length. And checking when enemy is near to the player by float value of length. This script is attached on enemy, so he has somehow range of attack. When player comes near, enemy attacks.
If you imagine enemy eg. as spider.
On the picture spider head is facing down. Should attack only what he see and this is the reason why I want make detection circle only by half (so red part shouldnt be taken, because of his back).
And of course enemy can rotate, so even this red area should rotate too, depend on its front (head).

Any tips? ;)
thanks

Martin
Title: Re: attack range (circle) - use only part of it
Post by: Thore on May 02, 2019, 10:09:52 AM
First, there's an action called "Get Distance", either built-in, or in Ecosystem. For only getting half a circle, you can use the midpoint and check against that, e.g. check whether the target point is below the midpoint, and dismiss if it's above it. 
Title: Re: attack range (circle) - use only part of it
Post by: marvoc on May 02, 2019, 10:42:08 AM
Hi thanks,
 yes I could use this "Get distance". But this isnt main issue ;)
About that midpoint I can compare if V2 is below x (horizontal line), but spider can rotate so whole cutting plane is rotated too. As shown on the picture.
Or I misunderstand :)
And I can not use triggers.


Picture:
So in this case enemy(V1) shouldnt attack player (V2).
Title: Re: attack range (circle) - use only part of it
Post by: marvoc on May 02, 2019, 04:32:41 PM
I thought about it and maybe if I know rotation of that direction vector (V1 to V2) I could get what I want.
Is there way how to get it?
Title: Re: attack range (circle) - use only part of it
Post by: djaydino on May 02, 2019, 05:46:37 PM
Hi.
maybe 'Get Angle To Target' can help
Title: Re: attack range (circle) - use only part of it
Post by: Thore on May 02, 2019, 06:36:34 PM
I probably miss something. Usually, you have a game object which has an orientation. That’s why you can consider the non-attack area as “behind” the centre point in local space. Different angles, as in the second image, are simply done by rotating around, so that again, the red area is “behind”. I think the check needs to be in local space, whether the target has a positive axis value, or a negative one (provided that the front is positive vector).

Maybe my action is of some use,
https://hutonggames.com/playmakerforum/index.php?topic=19490.msg84970#msg84970

Title: Re: attack range (circle) - use only part of it
Post by: Prestonh on May 04, 2019, 01:38:47 PM
Hi again ;)
Im trying to resolve this problem:
I have an enemy (V1) and player (V2) vectors. I subtract them and get that line between. Then Im using "Get Vector Length" to get its length. And checking when enemy is near to the player by float value of length. This script is attached on enemy, so he has somehow range of attack. When player comes near, enemy attacks.
If you imagine enemy eg. as spider.
On the picture spider head is facing down. Should attack only what he see and this is the reason why I want make detection circle only by half (so red part shouldnt be taken, because of his back).
And of course enemy can rotate, so even this red area should rotate too, depend on its front (head).

Any tips? ;)
thanks

Martin


Have you tried to get the vector of the enemy and the player,  then vector operate for the dot product.   Which returns 1 to -1.  1 is facing same direction, -1 is facing opposite direction.  So if the returned value is above 0.  They would be in the white half of your circle,   Below 0. They would be in the red half.
Title: Re: attack range (circle) - use only part of it
Post by: marvoc on May 06, 2019, 03:53:09 AM
Hi all,
 so first I was thinnking use dot product + Get A Cosine to get correct angles. But before to do this, I tried "Get Angle To Target" as djaydino recommended. And I think is the same, so cool its working nicely everything within one node! :)
Thanks