V
V
Veros Game2021-05-09 12:38:43
C++ / C#
Veros Game, 2021-05-09 12:38:43

How to make a tree loot in a 2D game?

6097ae15331dd333275560.pngThere is a player, and an Ax tool, and I want to make it so that when the ax touches a tree (using animation), the life of the tree is taken away and it breaks and gives resources, but I don’t know how to do it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yupiter7575, 2021-05-09
@yupiter7575

Look, you have a player and an Ax tool, and you need to make sure that when the ax touches a tree (with the help of animation), then the life of the tree is taken away and it breaks and gives resources. Is it clear now?

R
rPman, 2021-05-09
@rPman

In general, two approaches (first, decide for yourself in the game)
when you pick up an ax, a skill appears / activates (an action is the same as walking, jumping, etc.) chop
- the skill should require that there is a tree in the radius of the skill and even for example, it must be selected (what the skill will interact with) otherwise it cannot be activated (it happens when, when the skill is pressed, the character automatically runs to the nearest object that he needs, it is convenient when you need to hit enemies with a sword)
- the skill does not require anything but it simply activates, affecting objects within the radius of the skill
, and there, if anything, it cuts
In the second case, quirks like an ax cuts down a bunch of trees at once are possible, but here instead of a radius, you can choose your own activation area, incl. just a segment, you can also stop processing the activation of the skill as soon as at least one desired object is detected.
From here, start looking for ways to implement.
For example, make an ax a separate object, and its interaction through collisions (suitable for the second option, but it seems to me that this is a noticeable slowdown, especially when there are a lot of characters with such an implementation of actions, because this is at least doubling objects).
You can make the ax just a property of the character (animation is still needed for the ax, so implement the model with the ax, albeit variable if you need a different appearance), i.e. this is not an ax hitting a tree, but a character hitting a tree, playing the hit animation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question