• Unity
  • Caterpillar movement

So I've made a climbing mechanic in my game, the character rotates according to the ground angle.

But I'm trying to figure out how i'd make the tail of the caterpillar-like character follow the rotations on the ground effectively.

Any ideas . ^. ?

Pic of what I'm trying to explain

Hình ảnh bị xóa do không hỗ trợ HTTPS. | Vẫn hiển thị

Related Discussions
...
  • Đã chỉnh sửa

Hmm. That's a good question.
It's not specific to Unity though.

My first instinct was to shoot a ray towards the ground to get the normal. But how would you get the ray direction per piece in the first place?

So actually, if I had to guess, you have to calculate the slopes between the positions of the pieces before and then after a given piece and average and average them out.
How are you getting those circles to stick to the floor/wall? That system may have some useful data that can be used.

If the terrain is static, build a high detail path, or a spline, according to your player movement and move each object along the path by the same amount of cumulated distance the player moved. You may want to enforce distance among the objects on a second pass. I'd avoid redoing raycasts.

Thanks for your feedback. It got the gears running, I forgot to post back here but I worked on it for a few days and here's what I got:

https://twitter.com/Soulgryn/status/822589608940683266 it's a video so can't really embed. (The terrain is Ferr2D by the way)

I store the ground angle in an array and have each of the back pieces mimic it with an offset, basically. In spine, they don't inherit rotation of course to allow for odd bending. Then you tweak the offset to fit with the lengths of the parts.

I already had the climbing built, moving a single object around a surface, so it was just applying those values to the skeleton.

Nice. So is that it? You figured it out?
Looks like it's jittering a bit. Nothing a bit of moving average code couldn't fix. Probably as a polishing step.

I just started using Ferr2D once it became clear Unity wasn't making their own in the short term.

How did you pull this off? Did you just have a relative ray from the main body bone? I've been trying to do something similar but having trouble with corners like that.


21 Jan 2017, 08:05


Ah, I see, so its not about historical data, it's just an offset from the previous piece. That probable is a challenge if it ever wants to cross gaps, right?

Yep! The jittering I think is the first parts rotation, moving the other parts slightly cause they're attached in a chain. I could probably smooth out the rotation.

The regular climbing system casts a ray downwards and smooths the angle of the sprite to the surface, I use that angle to add relative velocity forwards. I also calibrate the position using the ray length so it doesnt go in/out of the ground.

The tail parts don't know anything other than the rotation of the main sprite. Each frame, the angle of the sprite is saved in an array that each of the tail parts look at in a delayed fashion. Like part 1 looks at the rotation 5 frames ago, part 2 looks at the rotation 10 frames ago and so on. For speed variation I stretch out that offset smootly based on current velocity.