x


Please help me set up my inputs. Im pretty confused.

    if (Input.GetAxis("Vertical"))

{
        transform.position += transform.forward * moveSpeed * Time.deltaTime;

}

    if (Input.GetAxis("Vertical"))

{
        transform.position += -transform.forward * moveSpeed * Time.deltaTime;

}

    if (Input.GetAxis("Horizontal"))
{
        transform.eulerAngles.y += - turnSpeed * Time.deltaTime;

}

    if (Input.GetButton("Horizontal"))
{
        transform.eulerAngles.y += turnSpeed * Time.deltaTime;

}
}

How do i define which are positive and which are negative? - Do i have to set up two inputs per axis, i know this is probably a silly question (i apoagies.) but im really struggling to find an appropriate solution.

Also, is there an easy way of setting it up detect the amount of force on the stick?

I would really appreciate your help - as always.

Thanks,

  • Graeme.
more ▼

asked Apr 19 '11 at 03:43 PM

Graeme P gravatar image

Graeme P
33 18 21 25

that last getbutton is ment to be axis too, just forgot to change it.

Apr 19 '11 at 03:44 PM Graeme P
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I am not a 100% sure on what you are trying to achive but anyways:

function Update ()
{
var horizontalSpeed = Input.GetAxis("Horizontal");

var verticalSpeed = Input.GetAxis("Vertical");

transform.position += transform.forward * verticalSpeed * Time.deltaTime;

transform.positon += transform.right * horizontalSpeed * Time.deltaTime;
}

You only need to use 1 axis at the time. Since Input.GetAxis returns form -1 to 1 and therefor it is unneccersary to use this twice:

if (Input.GetAxis("Vertical"))
{      
transform.position += transform.forward * moveSpeed * Time.deltaTime;
}   
if (Input.GetAxis("Vertical"))
{      
transform.position += -transform.forward * moveSpeed * Time.deltaTime;
}

but simply use:

   var verticalSpeed = Input.GetAxis("Vertical");

   transform.position += transform.forward * verticalSpeed * Time.deltaTime;
more ▼

answered Apr 19 '11 at 04:41 PM

OrangeLightning gravatar image

OrangeLightning
5.4k 47 57 112

Thank you for your help, exactly what I needed! =) - I really appreciate you guys sharing your knowledge.

Apr 19 '11 at 09:35 PM Graeme P
(comments are locked)
10|3000 characters needed characters left

You don't actually need two seperate ones. Just use one for each! Horizontal means both left and right, with one (I think left, but check this) being negative and the other positive. Same with Vertical --- it accounts for both. So just lose some of the excess statements, and it'll be fine.

more ▼

answered Apr 19 '11 at 03:57 PM

Muzz 1 gravatar image

Muzz 1
548 52 59 71

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x953
x520
x60

asked: Apr 19 '11 at 03:43 PM

Seen: 1020 times

Last Updated: Jul 18 '11 at 09:17 PM