I have the following script im am creating
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function Update()
{
if (grounded)
{
if (Input.GetButton ("Jump"))
{
moveDirection.y = jumpSpeed;
}
if (Input.GetButton ("left"))
{
moveDirection.x = speed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
I have followed the error messages advice and went to edit >project settings but the left and right buttons are assigned perfectly fine
I want my character to move with left and right keys and jump with the space key
its a 2D platformer game
Any suggestions unity experts lol
tonyd
November 1, 2010, 4:29pm
2
Is the ‘Jump’ button set up?
yeah no error reports for the jump button
system
November 1, 2010, 6:14pm
4
Have you checked the 2d sidescroller tutorial? Not asking to be annoying, but a lot of the problems I have I can usually pinch ideas/script from one of the tutorials and in this case, the 2d sidescroller tut…
Make sure that the “Name” of the input axis is “left” exactly. If it’s “Left” it won’t work, because capitalization matters. The key you set for the input axis isn’t what it’s checking, just the name of the input axis.
thanks for all your suggestions
funily enough, i did look at that example when I lost the will to live with all the errors i was getting lol
I still struggled understanding most of the code but al keep going through - its a learning curve
I shall go check once more for the Left // left suggestion Gargerath
let you know what happens in a bit
I found a work around after a while of pondering over Vector3() and corrisponding axis
although the buttons for left and right arent being recognised ; this works just as I wanted it to anyway
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function Update()
{
if (grounded)
{
moveDirection =new Vector3(0,0, Input.GetAxis(“Horizontal”));
moveDirection = transform.TransformDirection(moveDirection*-1);
moveDirection*=speed;
if (Input.GetButton (“Jump”))
{
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)