Using the input Keys predefined is easy enough, but how do I reference Horizontal Positive (Right) ?
I dont see how to add new buttons called UP DOWN RIGHT LEFT, so im trying to work with what is there. All im trying to do is get something to happen when the right left up down keys are pressed.
Just to further clarify, when a control is defined as an axis it has a positive and a negative part. So “Vertical” defines up as positive and down as negative. When you use GetAxis you get either a positive or a negative value, and it’s up to your code to define what to do with those values.
You can filter for positive or negative values as in Smallcode’s example, but it’s usually preferable to use the control’s return value in a way that you don’t have to do that - for example multiplying a rotation value by the axis for left/right rotation.
If you only want one type of input from a control (and not an axis) then you can define new buttons in the Input Manager (buttons only return positive values for a given control, like “Fire” or “Jump”).
Im not sure if the X/Y are correct in the TransformDirection to move it specifically up or down, but I know that this should at least move the object in different directions per different keystrokes. Does anyone see why this would only move my plane in one direction, up, no matter what I change?
if (Input.GetAxis(“Vertical”) > 0) {
var a= transform.TransformDirection(0,0,50); //up
controller.SimpleMove(a* speed);
}
if (Input.GetAxis(“Vertical”) < 0) {
var b= transform.TransformDirection(0,50,0); // down
controller.SimpleMove(b* speed);
}
if (Input.GetAxis(“Horizontal”) > 0) {
var c = transform.TransformDirection(50,0,0); //right
controller.SimpleMove(c* speed);
}
if (Input.GetAxis(“Horizontal”) < 0) {
var d = transform.TransformDirection(-50,0,0); // left
controller.SimpleMove(d* speed);
}
if (Input.GetAxis(“Vertical”) > 0)
{var a= transform.TransformDirection(0,50,0); //up
controller.SimpleMove(a* speed);}
if (Input.GetAxis(“Vertical”) < 0)
{var b= transform.TransformDirection(0,-50,0); // down
controller.SimpleMove(b* speed);}
your plane was constantly moving up as your first vertical is moving on the z axis and your second vertical is constantly moving up on the y axis… also just to not lag the game set some limits on all axis
If you only need the value of the axis, remove the comparison.
If you also need comparisons, use if statements.
Since you’ve already necro’d this thread => there is already shown how it works.
Seems like you should get a little more confident with the basic syntax, types etc.