# Simple Slide based movement down a hill

I'm a new unity user (pretty much brand new) and I'm working on scripting a natural yet controllable sled-like motion down a slope. Its kinda like Bowling in a sense. I wanted to implement physics going down the hill so that the acceleration is controlled by gravity. Heres an attempt that I whipped up after looking at some controller script examples that aren't quite what i've been looking to do(some variables haven't been used yet):

``````var speed = 3.0;
var jumpSpeed = 8.0;
var gravity = 10.0;

var smoothSpeed = 10.0;
var smoothDirection = 10.0;

var canJump = true;

private var moveDirection = Vector3.zero;

private var moveSpeed = 0.0;

private var grounded : boolean = false;
private var jumping : boolean = false;

private var verticalSpeed = 0.0;
function Update () {

var sideForce = Input.GetAxis ("Horizontal") * sidewaysPush;
var rotation = Input.GetAxis ("Horizontal") * rotationSpeed;
rigidbody.centerOfMass = Vector3 (balancePoint.x, balancePoint.y, balancePoint.z);

transform.rotation.y = Mathf.Clamp(transform.rotation.y, -80.0, 80.0);

// Make it move 10 meters per second instead of 10 meters per frame...
sideForce *= Time.deltaTime;
rotation *= Time.deltaTime;

constantForce.force.z = sideForce;
transform.Rotate (0, rotation, 0);
}

``````

I do also plan to allow jumping but for now I wanted to get the basic movement down. I just can't seem to get good control over the direction that I turn nor can I seem to control the rotation of the attached rigid body. The best thing I tried was to change its center of mass, it helped but now when I hit walls I end up with an unrealistic rotation if I separate from the ground.

use a rigidbody and AddForce method to move it in the way that you want. change the friction values to have the kind of movement that you want. you can use AddTorque if you want to rotate the ball more. sometimes when you rely on gravity to move your ball you don't get what you want. you can edit the gravity in edit/project settings/physics. size your bjects correctly. don't use a collider with radius of 0.5 if you don't want a huge ball.

This is a partial answer to the rotation problem.

Try using AddTorque() or AddRelativeTorque() to affect the rotation of a rigidbody rather than changing the GameObject transform directly.

``````rigidbody.AddRelativeTorque(0, -10, 0);

``````

Something like that. Be aware that the center of mass will affect the result of course.

http://unity3d.com/support/documentation/ScriptReference/Rigidbody.html

Also note that with physics, ie Rigid Bodies you should use FixedUpdate() rather than Update() because FixedUpdate() is fixed to the physics integration steps for consistent behaviour.

I hope that helps.