Scripting Movement Question.

What I’m trying to create is this.

Short Video
http://www.andrewjb.com/anim_pnr.html

This was done originally in Maya. Which of course I know never means it will work exactly alike in a game engine. All the movements will be set on a grid. One movement being moving to the next grid center.

My question is regarding the movement. I’ve tried two different solutions;

The first is using the time.deltaTime * the movement speed, and detecting collisions using a collider sphere attached to the bottom of the object. When I use the frame independent movement the object seems to bury into the object it’s colliding with. I know this is caused by the object moving faster than the size of the sphere collider. I’m using a script to adjust the position of the moving object to be exactly the correct distance from the on it’s colliding with. The problem is the correction creates a bouncing effect for a brief instance. Is there a better solution to this?

The second is using a frame rate dependent movement. This works exactly how I’d like it to work everything stops exactly where it should. The problem is that this is dependent on the frame rate.
And may vary depending on the comp.

My question is this. Am I better off using frame rate dependent or independent?

I think you’d be better off handling the movement programmatically using an array for the grid rather than trying to use the physics engine, something along these lines.

–Eric

I don’t know, this could be done with the physics system, so long as you used a 0% bouncy and 0% friction physic material and parented the box to the carrying character. If all the characters are represented by a box collider, you’ll get perfectly stacking objects just fine. The only issue, of course, is that you’ll need to restrict movement on the z-axis and keep your characters from sliding out of the level.

Still, it’s possible. Not extremely simple, but possible.

I had thought about doing something similar to using a zero bounce and zero material. But how would I go about restricting movement in the Z axis? That’s about the only part that I couldn’t figure out.

You can apply a force to the object proportional to its position on the Z axis (to push it back to zero if it ever moves):-

var holdingForce: float;
var damping: float;
   ...

function FixedUpdate() {
    var dampValue: float = Mathf.Abs(rigidbody.velocity.z * damping);
    var force: Vector3 = -transform.position.z * (Vector3.forward * (holdingForce - dampValue));
    rigidbody.AddForce(force);
}

The damping is to prevent the object oscillating endlessly if it gets moved in the Z direction.