How to get a rigidbody to stick and roll on a moving terrain?

Discussion in 'Physics' started by Kaji-Atsushi, Oct 25, 2015.

1. Kaji-Atsushi

Joined:
Oct 6, 2012
Posts:
234
Greetings all!
The short version:
Anyone knows how to make a free physics enabled rigidbody2D 2Dcircle stick to a rapidly moving terrain. I mean stick on the y-axis change of the terrain. The ball is still free to "roll around"

The long version:
I've been hitting my head against this problem for...3 weeks or...maybe even more(apparently I'm still quite the noob). I think it's a relatively simple problem, so I'm trying my luck here because I've googled and tried all sorts of things.

The idea is to have a moving terrain with a physics rigidbody2d enabled circle rolling around on it, but never exiting it's collision from the collider, or in other words, it's sticking to the terrain, for this case, the terrain is made up of a couple of EdgeColliders and it's vertex point is being moved around in relatively random directions and speed.

The circle is really simple, it's just a simple circle with a circle collider and a rigidbody. All I want it to do is roll around and never lose contact with the terrain. So if the terrain lowers itself at a high velocity, i don't want the the circle to drop at a slower rate, I want it to drop, and continue to react/roll with the slopes and hills of the terrain.

I've tried increasing gravity and tweaking angular drag or linear drag, That gets me a close result, but it's still possible for the circle to lose contact with the terrain, and I can't have that.

I've also tried a CircleCast and manually setting it's position with "MovePosition" to the point of collision/centroid. While that does work quite well, it creates the side effect of DRAMATICALLY slowing down the Circles natural rolling down the slopes speed.

Naturally, I tried to counter-act it by increasing the gravity, and while I was able to achieve the roll speeds I wanted by increasing the gravityScale to a ridiculously high number. It introduced another side effect, whenever the circle would rest in the pit vertex of the terrain, it would jitter. If I set the gravityScale back to a reasonable range 1-10, it jitters less. But then the circle moves as slowly as a snail down a hill. When I amp it up to...500. I get the natural ball rolling down the hill speed but lots of jitter at the vertex.

I've considered using the sliderjoint2d, but I don't want to go down that troublesome road of figuring out the colliders and switching from a slider to another slide and retaining it's velocities without having a weird result.

If anybody has any ideas on another way to approach this problem please let me know, Thanks!

I've provided screenshots to show you what I meant terrain made with two edge colliders and the vertex point changing positions.

Attached Files:

File size:
107.1 KB
Views:
464
File size:
52.4 KB
Views:
669
• Screen Shot 2015-10-24 at 8.30.46 PM.png
File size:
104.1 KB
Views:
452
Last edited: Oct 25, 2015
unityunity