So, This Basic Movement script, causes me to have a break-dancing cube which is uncontrollable.
#pragma strict
var speed = 1.0;
var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)
Please note, this is BEFORE i hit a button aswell as after
Instead of using Input.GetKeyDown(KeyCode.W)
go trhough unity’s inputs. so use this code instead,
if( Input.GetAxis ("Vertical") > 0)//You only want the positive
transform.position += transform.forward * moveSpeed * Time.deltaTime;
For more information, go to the GetAxis documentation, found here:
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetAxis.html
I figured it out, it’s because I had a Box Collider already, and was using a script to create a CharacterController, My guess was that they were colliding with eachother, causing the Box Collider to “Bounce”
senad
January 16, 2013, 9:34am
3
Your problem is not in this part of code, because it looks fine.
You should have a look at what changes you made between recently (start of broken behaviour) and now to find out what code broke your movement.