QuirkyCort / gears

Generic Educational Robotics Simulator
Other
65 stars 41 forks source link

Only apply damping in perpendicular directions. #72

Closed sgmurray closed 3 years ago

QuirkyCort commented 3 years ago

Works well enough that I'm making a small dGain (0.08) the default, and removing the setDamping for magnetic items (...but not for the football world which still needs it to slow down the ball).

There's a small bug when the parent of the magnet has a parent itself, but I've fixed that.

One issue is that the damping applies to all perpendicular movement, and as a result, the attracted object moves like in picture 2, instead of what it should (picture 1).

path4153-6

Not so obvious with the ball due to its large size, but much more noticeable when picking up small objects.

I've added in an additional condition, so that the damping will only apply if the movement direction is greater than 60 to the magnet axis. Seems to help.

sgmurray commented 3 years ago

I am able to get movement more like picture 1 by setting normalVec to vec.normalize():

let error = meshVel.subtract(bodyVel); //let normalVec = self.attractor.up.clone(); let normalVec = vec.normalize(); error.subtractInPlace(normalVec.scale(BABYLON.Vector3.Dot(error, normalVec)));

QuirkyCort commented 3 years ago

Not gonna pretend I know how that works, but it does, and it's better.

I'm switching to that. Thanks!