Rigidbody Version of RotateAround

I'm making a game and the current script uses transform.RotateAround to move in a circle around another game object. The down side of this is that the game object moving will go through other Trigger colliders, making it useless against another set coding I have. I need some way to manipulate the rigid body by converting Transform.RotateAround.


    var degree: float = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
    transform.RotateAround (Target.position, Vector3.up, -degree);
    //Moves towards the target or away depending on up or down key
    var translate: float = Input.GetAxis ("Vertical") * speed * Time.deltaTime;
    rigidbody.AddForce(0, 0, translate * 50);

Trigger Script:

function OnTriggerEnter(other: Collider){
rigidbody.velocity = -rigidbody.velocity;

For the trigger: You don't need triggers to bounce stuff off though. Just use a regular collider without any renderer. You can set layermasks so it only affect the ball if you want. Finally you could apply a bouncy physics material to it so it bounces right off.

For the controls: I toyed around a bit with this. See if this is somewhat like you expect.

I created a webplayer so you can try the controls in action.

var speed = 10.0f;
var target : Transform;

function FixedUpdate () {

    var horizontal = Input.GetAxis("Horizontal");
    var vertical = Input.GetAxis("Vertical");

    var direction = (target.position - rigidbody.position).normalized;
    var rotation = Quaternion.AngleAxis(horizontal * 60, Vector3.up) * direction * Mathf.Abs(horizontal);
    var desired = rotation + vertical * direction;
    var change = desired * speed - rigidbody.velocity;

    // Debug lines: Red - current heading
    //              Blue - applied heading
    Debug.DrawLine(rigidbody.position, rigidbody.position + rigidbody.velocity, Color.red);
    Debug.DrawLine(rigidbody.position, rigidbody.position + change, Color.blue);

    rigidbody.AddForce(change * Time.deltaTime, ForceMode.VelocityChange);

You could use Rigidbody.AddTorque or Rigidbody.AddRelativeTorque.


var torque : float = Input.GetAxis("Horizontal");
rigidbody.AddRelativeTorque (0, torque, 0);

(And remember: Put all physics related stuff in the function FixedUpdate.)