I'm moving a player around the inside of a hollow sphere equipped with a non-convex mesh-collider. The player is meant to walk along the inner surface of the sphere with a gravitational pull towards the ship hull (away from the center). For the gravity, I've attached a modified version of this script to the player:
using UnityEngine;
using System.Collections;
public class Gravity : MonoBehaviour
{
//credit some: podperson
public Transform planet;
public bool AlignToPlanet;
public float gravityConstant = -9.8f;
void Start()
{
}
void FixedUpdate()
{
Vector3 toCenter = planet.position - transform.position;
toCenter.Normalize();
GetComponent<Rigidbody>().AddForce(toCenter * gravityConstant, ForceMode.Acceleration);
if (AlignToPlanet)
{
Quaternion q = Quaternion.FromToRotation(-transform.up, -toCenter);
q = q * transform.rotation;
transform.rotation = Quaternion.Slerp(transform.rotation, q, 1);
}
}
}
Unity's default movement controllers don't seem to work with this Gravity script, so I fashioned a simple one (forward/backward movement only):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class NewController : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
private void FixedUpdate()
{
GetComponent<Rigidbody>().AddForce(transform.forward * CrossPlatformInputManager.GetAxis("Vertical"), ForceMode.Impulse);
}
}
It works in that I'm able to walk around the inside of the sphere. It's very bumpy though, presumably because the forward force causes the player to constantly run into the corners/edges of the sphere polygon, and because these incongruities are not corrected quickly enough by the "AlignToPlanet" Quaternion in the gravity script.
To sum up, I need a way to move smoothly along the inside of the sphere. I'm not sure if this needs to be solved with code or values in the Unity Editor (regard drag, etc.).