This script is very similar to my Drop to Ground script (99% of guts are the same), but the functionality is different enough that I felt it deserved it’s own notice.
You can use this script as an object link through the script buttons. You can link it as a FrameChange or Redraw script, but I’ve found it fast enough (and fun) to use as a Redraw script.
When linked, it snaps the object center of the linked object to the surface of the mesh object called “Ground”. If you’re not over the Ground object, you move freely. If, however, you’re over the Ground object, then your linked object is free to move along in x and y, but follows the contour of the terrain.
So - if you want something to move along an irregular surface, all you have to concern yourself with is x and y movement - this script moves your object up and down according to the mesh it’s sitting on. It works with live motion in the 3D window and with keyframes. I haven’t gotten it to work with FollowPath constraint yet (which would rule, btw). It should be able to work in conjuction with other scripts that generate x and y motion (walking scripts, etc.).
In the sample .blend, the both the red and yellow balls are linked to the script. The red ball is for free-form play. The yellow ball has been given a couple of keyframes - hit alt-A to see it climb the hill!
Here’s the script, in a .blend:
Different script for riding the terrain for an object that is constrained to follow a curve:
It should work for any translation of the curve, but I wouldn’t go rotating or scaling it. So, with this version of the script, you should be able to take a 2D path that you’ve drawn over your terrain, give your object a FollowPath constraint to the curve, link the object to the script, and watch it follow the contour of the ground object while it follows the curve.
I’m going to try to generalize the script so a single version works in both cases (pathed and non-pathed).