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.