- Home /
FPS Controller Question Again !!
Hey Guys,
I am having some problems with my script basically if i press A the plater will move to the left. But if i press D he will still move to the right why is that?
here is my script:
42 42
public var MoveSpeed: float = 15;
public var MoveLSpeed : float = 5;
function Update () {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0){
var MoveFWD : float = Input.GetAxis("Vertical")* Time.deltaTime * MoveSpeed ;
transform.Translate(Vector3.forward * MoveFWD);
}
if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0){
var MoveLeft : float = Input.GetAxis("Horizontal")* Time.deltaTime * MoveLSpeed;
transform.Translate(Vector3.left * MoveLSpeed);
}
}
@script RequireComponent (CharacterController)42
42
I would be really thank full if someone can help me :)
Dude...! -.- I've been retagging 'unitysomthing' tags for easily over an hour now... and a particularly big share of those single-use-tags were from you.
Everything here is about unity anyway, so why have 'unityfps' additional to 'fps'?
So, please keep in $$anonymous$$d for the future: adding Tags just for fantasy's sake doesn't make any sense and makes a Sister$$anonymous$$y very unhappy =(
Greetz, $$anonymous$$y.
@Sister$$anonymous$$y Lol sorry about that i will stop that :) i know it is annoying because every question i put up regarding unity FPS i always put those tags sorry :) i will stop that :)
Answer by aldonaletto · Jul 03, 2011 at 01:01 AM
You're making the same mistake as before; you should use MoveLeft instead of MoveLSpeed:
transform.Translate(Vector3.left * MoveLeft);
EDITED: If you're using a Character Controller, you should move the character using Move. There's a good and simple example in CharacterController.Move - it moves the character, respect collisions, uses gravity and can even jump! Here's a copy of this script:
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
oh hahahahah i am such an ass lmao :) thanks man i really am blind lol
oh yeas can you please help me with the gravity thing Please you know if grounded etc and using flags. Please thanks
Since your character is a Character Controller, you must not use translate - it ignores collisions. I'm editing my answer to include this matter.
oh thank you :) i have faced that problem because when i walked next to walls he walked right trough them :) thank you :)
Check the answer: it was edited to include a good example script.
Your answer
Follow this Question
Related Questions
CHARACTER MOVEMENT?! 1 Answer
Standard Asset First Person Controller FPS Problems 0 Answers
Click Once to play an entire animation 2 Answers
How to display Gui for clips left - FPS tutorial 0 Answers
Collider causes terrible lags 1 Answer