- Home /
How To Improve my Rigid Body Sphere Character Controller
Hello All, I'm currently working on making a simple game that uses the a sphere with a rigid body as the character. I use a rigid body sphere because I want to make some mini-games using Unity's Physics. Unfortunately I can't seem to find any built in one so I wrote my own.
Here are my problems: 1. The controls are unresponsive, it takes a while for your character to change velocity to a different direction. 2. I haven't been able to find a way to cap the max speed. 3. Once again, controls are VERY Unresponsive. Any Ideas?
Here is my current code. // Include Unity Assets using UnityEngine; using System.Collections;
// Declare our class
public class launchRampTrigger : MonoBehaviour
{
// Imnspector Variables
public GameObject player;
public float moveSpeed;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
// Store our axis numbers for movement
float horizontalAxis = Input.GetAxis("Horizontal");
float verticalAxis = Input.GetAxis("Vertical");
////////////////////////////
// Move Player
rigidbody.AddForce (Vector3.forward * moveSpeed * Time.deltaTime * horizontalAxis);
rigidbody.AddForce (Vector3.right * -moveSpeed * Time.deltaTime * verticalAxis);
}
}
And sorry the file has a weird name, I forgot to change it's name ha..
Answer by BlackWingsCorp · Jun 02, 2013 at 10:21 AM
I have a couple of suggestion: 1)use something like this: public class NewBehaviourScript : MonoBehaviour {
public GameObject player;
public float speed = 20;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.UpArrow)){
player.transform.position = transform.forward * speed * Time.deltaTime;
}
}
}
//use the same technique for the rest of the directions. change the value of "speed" to change the speed
2)add the first person controller component to the sphere. then change the camera, speed, etc in the inspector view
Hope it helps
Answer by robertbu · Jun 03, 2013 at 06:01 AM
Object turn faster:
Increase the drag (0 by default) in the Rigidbody, and increase the force applied each frame. Increasing the drag will cause the existing velocity to decay faster and the new velocity to be more "meaningful."
You can "turn" the velocity instead of adding force. The object will then turn instantly.
To restrict speed:
You can scale the force applied each frame so that at higher speeds, no force is applied.
You can limit the velocity directly:
if (rigidbody.velocity.magnitude > some_value) rigidbody.velocity = rigodbody.velocity.normalized * some_value;
Your answer
Follow this Question
Related Questions
Unity 4 to 5 Character Controller Issue 1 Answer
Character Controller problems with a space ship 1 Answer
Do character controllers work with dynamic gravity? 1 Answer
How to detect angles of walls? 1 Answer
Gun collision problem 3 Answers