- Home /
How to make object roll in an arch?
This is the code so far I'v got to make it roll and move nicely :
#pragma strict
function Start () {
}
var PlayerJumpSpeed : float = 5.0;
var MaxJumps : float = 30.0;
var PlayerRollSpeed : float = 100.0;
var rotationSpeed : float = 30.0;
var maxRadiansDelta : float = 30.0;
var maxMag : float = 30.0;
var movementSpeed : float = 20.0; /* Block speed */
function FixedUpdate ()
{
var movement = (Input.GetAxis("Horizontal") * -Vector3.left * movementSpeed)+(Input.GetAxis("Vertical") * Vector3.forward * movementSpeed);
rigidbody.AddForce(movement, ForceMode.Force);
// move player by letting them roll the ball
//var rot :float = Input.GetAxis("Horizontal") * Time.deltaTime;
//rigidbody.transform.Rotate(0,rot,0);
Vector3.RotateTowards(Vector3.left,Vector3.left,maxRadiansDelta,maxMag);
var torque = Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal"));
//torque = Camera.main.transform.TransformDirection(torque);
//torque.y = 0;
rigidbody.AddTorque(torque.normalized*movementSpeed);
/*if (Input.GetKeyUp("space") && Physics.Raycast(transform.position, Vector3.down, MaxJumps))
{
rigidbody.AddForce(Vector3.up * PlayerJumpSpeed, ForceMode.Impulse);
}*/
}
however it doesn't turn in an arch like i want it to,reason i want it to turn in an arch coz it would be player friendly,i want them to make a quicker turn to the left or right,I'v tried with the Rotatetowards but to no avail,not sure what to put in the arguments.Thank you.
Answer by robertbu · Mar 14, 2013 at 03:14 AM
I'm not sure of the mechanics of your game, but one way to create is a curve is to use a small amount of side force each frame. To calculate that side force, you need the cross product of two vectors. Start with Vector3.up and rigidbody.velocity. You can use the axis of rotation of the ball instead of Vector3.up. Which vectors you choose will depend on your game. The call will be something like:
rigidbody.AddForce(Vector3.Cross(rigidbody.velocity, vector3.up) * amount));
Depending on what you are doing, you may need to reverse the parameters to the Vector3.Call() or negate the resulting vector.
Your answer
![](https://koobas.hobune.stream/wayback/20220613094353im_/https://answers.unity.com/themes/thub/images/avi.jpg)