Hi, total amateur here. Last time I dealt with coding was…jeez, almost 10 years ago
I’m building a sort of top-down game that has jumping and platforming, and gravity is refusing to work (kind of a necessity).
I started with a player movement script from the Tornado Twins’ Wormageddon tutorial:
var speed = 3.0;
var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
//rotate around y axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
//move forward, backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)
The gravity works fine with this script, but the motion isn’t what I’m looking for (run left/right, not turn). So, I looked around for a bit and found a fairly simple one that did what I wanted, but the gravity didn’t work. I borrowed the CharacterController elements from the Tornado Twins’ script in an attempt to trigger the missing gravity, but to no avail:
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
if (Input.GetKey ("up")) {
transform.Translate(0,0,.1);
}
if (Input.GetKey ("down")) {
transform.Translate(0,0,-.1);
}
if (Input.GetKey ("right")) {
transform.Translate(.1,0,0);
}
if (Input.GetKey ("left")) {
transform.Translate(-.1,0,0);
}
}
@script RequireComponent(CharacterController)
The CharacterController aside, what am I missing from the Twins’ script, and how might I implement it?
In the interest of getting a confirmation out of an educated guess, is it curSpeed? Should I add a speed var and have a curSpeed equal it? Should I perhaps just include curSpeed = 0.3 or something?
Thanks in advance.