E
E
Emil2019-02-23 01:24:47
Mobile development
Emil, 2019-02-23 01:24:47

How to implement a battle in the game (track the reaction to contact within a certain radius according to the principle of friend or foe) in a 2D game?

Good night everyone, please share your experience.
I am developing a mobile game, I need to implement a battle system. The essence is simple, a person clicks on the character icon and he spawns going to the right (towards opponents who automatically go to the left)
How to realize the possibility of detecting each other so that when they are in a certain radius, they stop and start fighting.
I'd be happy to help, and thanks in advance.
PS
About how to spawn and direct in the right direction, I know, but specifically that they would see each other and begin to react to this event, no.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2019-02-23
@DyadyaEmil

1) The distance formula (@yayashitoya wrote almost correctly - there is also a root, or a quadratic radius)
2) Directly in the unit there is magnitude and sqrMagnitude - the distance between Vector3
3) Well, you can also use colliders (triggers)

Y
yayashitoya, 2019-02-23
@yayashitoya

(X1-X2)^2+(Y1-Y2)^2<=R^2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question