Making a boat sail around a globe. How to I approach this?

Hello,

I’m trying to get a bunch of boats to sail around a sphere. Currently i have this working with character controllers that raycast down to see if we are still hitting the sphere. And i use the CC to move forward and I apply a rotation to my boat depending on the angle that i am from the sphere;s center.

However, collisions aren’t handled nicely. If the boats hit each other straight on that stop. Or if they hit a wall you will see them jitter up and down. At a later stage in my game i would want tornado’s to be able to pick up the ships and toss them about.

I was told CharacterControllers aren’t the nicest component to use so i’ve been trying different approaches to get this to work. Ideally i thought to use rigidbodies with a collider and a custom script to control it, but the movement isn’t as precise as it was previously.

What would be a good way to get good collisions (potentially i could avoid walls with some steering behaviors) and still be able to control my ships more precisely?

Cheers

Char controller is probably the problem here. I think a simple capsule turned 90 to face forwards is all you need. Then you use very basic commands like addforce and torque to control rotation and movement forwards. Simply make a gameobject that’s separate with the capsule collider, so you can orient and position the collider so it correctly defines the shape of the boat best as possible.

Add a rigid body,

Then you can merely assign the boat mesh to be a child of this.

The char controller really isn’t designed for this, it has it’s own raycast code for stairs and so forth, I can’t see it ending well. also probably best to disable gravity on boats and control the height entirely yourself (if not already doing so).

I really liked your prototype :slight_smile: I guess a little polish on physics is all you need. I know from personal experience, physx can do any sort of look and feel you can think of, it’s just a matter of experimentation.

You could try adding custom gravity, pulling towards the sphere’s center, instead of using ray casts. Might result in better physics, but could be tough to get right.

Like hippocoder said, a character controller is probably not suited for this special case.

Thanks for the replies,

Right now i’m experimenting using as a downward force:

rigidbody.AddForceAtPosition(
                          Physics.gravity.magnitude * (planet.position - transform.position).normalized,
                          transform.position - transform.up,
                          ForceMode.Acceleration
);

But sometimes it makes my test object dive face first into the sphere after a small distance travelled. Perhaps this has to do with mass/drag?

Let’s assume i setup an empty gameobject with a capsule rotate 90 degrees to best represent the shape of the ship. I add a rigidbody to it for the physics and manipulate it with it’s methods: AddForce/Torque/AtPosition. Is there any order required in executing these functions? And how do mass/drag factor in?

Messing around a little with some of your suggestions. So far so good. Setup a horizontal capsule collider, rigidbody attached and i get it to move around the sphere and rotate accordingly… However, it’s not hugging the surface of the sphere anymore ;(

void FixedUpdate()
{
	if(Input.GetAxis("Horizontal") != 0)
		rigidbody.AddRelativeTorque( 0f, 8f * Input.GetAxis("Horizontal"), 0f );
	
	rigidbody.velocity = transform.forward * 8;
	rigidbody.AddForceAtPosition(
	                             Physics.gravity.magnitude * (Vector3.zero - transform.position).normalized,
	                             transform.position - transform.up,
	                             ForceMode.Acceleration
	                             );
}

EDIT: Apparently setting the velocity directly is causing the behavior. Using AddForce() is causing my boat to rock uncontrollably as well.

great succes: superflat.nl