fmp 05/11/2022

In fact, when I made the spider standby animation yesterday, I had already thought about the spider’s attack logic.

But before I start to introduce all this, I need to introduce a very useful function: Bezier curve.

Bezier curves are widely used in modern computer graphics. Bezier curves are often used to describe surfaces and curves, such as the pen tool in photosh. But we only use it here to describe a curve, and the curve can have multiple control points.

Bézier curve – Wikipedia

The complete concept of Bezier curves can be found in the above Wikipedia link.

Because I couldn’t find a similar tutorial in the Simplified Chinese online community, I even recorded a tutorial for this purpose, and got 4000 views. The tutorial I made myself can click the link below.

https://www.bilibili.com/video/BV1xP4y1U7J8?t=3.6

After a simple tutorial of the mathematics part, then let’s begin to see the spider’s attack logic.

The upper left corner of the picture shows the attack range of the spider legs. The attack event is triggered when the player walks into the attack range.

The lower right corner of the image shows the spider leg attack. A1 in the figure is the starting point of the spider’s leg, A3 is the player’s current position, and A2 is a control point calculated by interpolation between A1 and A2.

In this way, I only need to go through the positions of the ends of the six spider legs and the character to get the spider leg closest to the player.