Quantcast
Channel: Questions in topic: "input.getaxis"
Viewing all 266 articles
Browse latest View live

how to simulate keyboard left right keys to touch button in unity 4.6 ?

$
0
0
torqueDir = Input.GetAxis ("Horizontal"); if (torqueDir != 0) { rigidbody2D.AddTorque (3 * Mathf.PI * torqueDir, ForceMode2D.Force); } else { rigidbody2D.AddTorque (0); } slope = transform.localEulerAngles.z; //convert the slope values greater than 180 to a negative value so as to add motor speed //based on the slope angle if (slope >= 180) slope = slope - 360; // dir = Input.GetAxis ("Horizontal"); Debug.Log (dir); if (dir != 0) //add speed accordingly motorBack.motorSpeed = Mathf.Clamp (motorBack.motorSpeed - (dir * accelerationRate - gravity * Mathf.Sin ((slope * Mathf.PI) / 180) * 80) * Time.deltaTime, maxFwdSpeed, maxBwdSpeed); //if no input and car is moving forward or no input and car is stagnant and is on an inclined plane with negative slope if ((dir == 0 && motorBack.motorSpeed < 0) || (dir == 0 && motorBack.motorSpeed == 0 && slope < 0)) { //decelerate the car while adding the speed if the car is on an inclined plane motorBack.motorSpeed = Mathf.Clamp (motorBack.motorSpeed - (decelerationRate - gravity * Mathf.Sin ((slope * Mathf.PI) / 180) * 80) * Time.deltaTime, maxFwdSpeed, 0); } //if no input and car is moving backward or no input and car is stagnant and is on an inclined plane with positive slope else if ((dir == 0 && motorBack.motorSpeed > 0) || (dir == 0 && motorBack.motorSpeed == 0 && slope > 0)) { //decelerate the car while adding the speed if the car is on an inclined plane motorBack.motorSpeed = Mathf.Clamp (motorBack.motorSpeed - (-decelerationRate - gravity * Mathf.Sin ((slope * Mathf.PI) / 180) * 80) * Time.deltaTime, 0, maxBwdSpeed); } """**this is a part of code it uses the keyboard horizontal axis to determine left and right input, i want to map the keys to the touch button on android in new ui 4.6**"""

How to get positive or negative button from axis in C#

$
0
0
Hello everyone! Quiq question. How to get positive or negative button from axis in C#? I need to use it in an "if" statement. GetKey(KeyCode) - NOT an option, writing code for joystick. Thanks in advance

Lerping from one position to another in a specific amount of time, no matter the distance

$
0
0
I'm playing around with a top down thingy where I want my character to control in a very specific way. The idea is that once I indicate a direction, the character starts moving in that direction until it hits a wall. My approach is: Have it shoot out a ray and note the hit point where it collides with an object that I've tagged as "wall". Once it hits a wall, it starts lerping towards that hit point. My problem is, I seem to be missing something about how lerping works and I can't seem to wrap my head around the logic. It will only lerp part of the way instead of lerping smoothly all the way. Here's my code: public class PlayerController : MonoBehaviour { public float speed = 30f; public float rotateSpeed = 15f; //Creating an enum to store my directional constants. I really need to learn about enums because I don't know what I'm doing exactly. enum Direction{North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest}; private Direction playerDir; private string direction; //A number based on hDirection and vDirection to let me set rotation to a single number private Vector3 fromPosition; private Vector3 targetPosition; private bool moving; private float moveCool; private float nextMove; RaycastHit hit; //Okay, so I create a Ray called "hit" void Start () { playerDir = Direction.North; moving = false; moveCool = 0.5f; } void FixedUpdate () { float moveHorizontal = Input.GetAxisRaw ("Horizontal"); float moveVertical = Input.GetAxisRaw ("Vertical"); //Detect input and start rotating the player if there is movement input if (moving == false) { if (moveHorizontal == 0 && moveVertical == 1) { playerDir = Direction.North; moving = true; Rotation (playerDir); } else if (moveHorizontal == 1 && moveVertical == 1) { playerDir = Direction.NorthEast; moving = true; Rotation (playerDir); } else if (moveHorizontal == 1 && moveVertical == 0) { playerDir = Direction.East; moving = true; Rotation (playerDir); } else if (moveHorizontal == 1 && moveVertical == -1) { playerDir = Direction.SouthEast; moving = true; Rotation (playerDir); } else if (moveHorizontal == 0 && moveVertical == -1) { playerDir = Direction.South; moving = true; Rotation (playerDir); } else if (moveHorizontal == -1 && moveVertical == -1) { playerDir = Direction.SouthWest; moving = true; Rotation (playerDir); } else if (moveHorizontal == -1 && moveVertical == 0) { playerDir = Direction.West; moving = true; Rotation (playerDir); } else if (moveHorizontal == -1 && moveVertical == 1) { playerDir = Direction.NorthWest; moving = true; Rotation (playerDir); } } if (moving == true) { if (Time.time > nextMove) { moving = false; Debug.Log (moving); } } } void Movement () { nextMove = Time.time + moveCool; nextMove = Time.time + moveCool; //I shoot the ray forward (this will always be after I have rotated, so that's fine) and let it continue until it hits something. //Maybe read up on "out hit" at some point. You don't know what you did there. if (Physics.Raycast(transform.position, transform.forward, out hit)) { //okay so when it hits something, it's gonna set the update fromPosition with the player's current position and then use the impact point from the ray //as the value in targetPosition. So far so good. print (hit.point); fromPosition = transform.position; targetPosition = hit.point; } transform.position = Vector3.Lerp (fromPosition,targetPosition,Time.deltaTime * speed); } void Rotation (Direction playerDir) { //switch statement - checks against multiple cases of a single variable (playerDir in this case) and takes actions based on different values of the variable. switch((Direction)playerDir) { case Direction.North: transform.eulerAngles = new Vector3(0f,0f,0f); Debug.Log (playerDir); Movement(); break; case Direction.NorthEast: transform.eulerAngles = new Vector3(0f,45f,0f); Debug.Log (playerDir); Movement(); break; case Direction.East: transform.eulerAngles = new Vector3(0f,90f,0f); Debug.Log (playerDir); Movement(); break; case Direction.SouthEast: transform.eulerAngles = new Vector3(0f,135f,0f); Debug.Log (playerDir); Movement(); break; case Direction.South: transform.eulerAngles = new Vector3(0f,180f,0f); Debug.Log (playerDir); Movement(); break; case Direction.SouthWest: transform.eulerAngles = new Vector3(0f,225f,0f); Debug.Log (playerDir); Movement(); break; case Direction.West: transform.eulerAngles = new Vector3(0f,270f,0f); Debug.Log (playerDir); Movement(); break; case Direction.NorthWest: transform.eulerAngles = new Vector3(0f,315f,0f); Debug.Log (playerDir); Movement(); break; } } Also, I am very much a newbie at this, so feel free to also point out any redundancies or sub optimal practices. :) Thanks

Managing input for several players using pads in the same computer.

$
0
0
The "tl;dr" question about input, could be: Which is the best way to manage several players (up to 4), each using its own Xbox 360 controller, in Unity? The long version follows: As the tl;dr says, I'm trying to manage 4 players in the same screen. I read some time ago about [the input manager that Unity uses][1], but read somewhere that it was really buggy, and that its better to write your own, so thats what I did. I have my "inputController" which receives a set of pre-configured keys (originally from keyboard) and asks about Input.GetKeyDown(key), Input.getKeyUp(key) and so. The characters moved along right and everything was nice. Then, I "upgraded" it to read also axis from a joystick (Input.getAxis("AxisName"+playerNumber)). Using a custom set of keys (joystickButton) I managed to get one pad working to move a second character, using 4 buttons, the left thumbstick and the triggers. So, the InputManager has now 4 "custom" axis: 2 for the thumbstick (horizontal and vertical) and the other two for both triggers. - My first problem is that I don't know how can I control a second pad plugged in the same computer. For what I've seen [here][2], for the buttons is easy as "joystickButton", where "n" is the number of the player (i.e. "Joystick4Button0"). The real problem comes with the axis. As I'm reading them from the "custom axis" I make in the Input inspector, **do I need to set up 4 custom axis for each new player, and make each player "read" the designated axis?** can I have several "Inputs", each copy of the other, but with different bindings? - The second problem is that what I've seen in the documentation is puzzling me now: **It seems that the idea is to allow the player redefine the controls through the "Input" tab** on the start menu, **but, of course, what I'm doing kind of overrides it completely**. Is Unity's standard Input handling reliable enough to be used, should I convert my class to work with it or I'm better handling everything by myself and not paying attention to this module? [1]: http://docs.unity3d.com/Manual/ConventionalGameInput.html [2]: http://ludumdare.com/compo/2013/08/29/multiple-xbox-controllers-in-unity/

C# Player Movement help?

$
0
0
Hey guys I've done a very basic player movement script where a capsule can go back and forth and rotate to turn around and stuff. What I'm trying to find help in is how do I make it so that the player movement moves around like the 3rd person controller? So that it will always walk on the Z axis of the object and just do like static turns at 90° and 45° if 2 buttons are pressed So like if you press up - doesn't turn at all, just moves forward press right - will turn 90° and move forward press up + left - will turn 45° and move forward. Any links that'll help me out or a tutorial or some kind of link will be greatly appreciated. public class CharacterControl : MonoBehaviour { public float rightSpeed; public float forwardSpeed; public float turnSmoothing = 15f; private CharacterController playerController; void Start() { playerController = GetComponent(); } void Update() { Vector3 forward = transform.TransformDirection(Vector3.forward); float fspeed = forwardSpeed * Input.GetAxis("Vertical"); Vector3 right = transform.TransformDirection(Vector3.right); float rspeed = forwardSpeed * Input.GetAxis("Horizontal"); playerController.SimpleMove(fspeed * forward); playerController.SimpleMove(rspeed * right); } void Rotating (float horizontal, float vertical) { Vector3 targetDirection = new Vector3(horizontal, 0f, vertical); Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up); Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime); rigidbody.MoveRotation(newRotation); } }

How do I correct no response from input keys

$
0
0
I'm using the Rogue-like tutorial and I keep failing to get the input controls correct. Either I get nothing or arrow keys do not take player more than one space right or up. My code straight from tutorial script online: if(!GameManager.instance.playersTurn) return; int horizontal = 0; //Used to store the horizontal move direction. int vertical = 0; //Used to store the vertical move direction. horizontal = (int) (Input.GetAxisRaw ("Horizontal")); vertical = (int) (Input.GetAxisRaw ("Vertical")); if(horizontal != 0) { vertical = 0; } if(horizontal != 0 || vertical != 0) { AttemptMove (horizontal, vertical); }

Simulate keyboard buttons to use Input.GetAxis ("Horizontal")

$
0
0
Hi, I've been stuck on this for a while and I would appreciate your help. I need to port a game to mobile devices and as a result I need to change the control scheme to take into account taps. I want to keep using Input.GetAxis ("Horizontal") since the game was built and balanced around it, and just simulate a left/right keystroke whenever a player taps on the left/right side of the screen. Is that in any way possible? **onUpdate:** touchMove() playerPosition.x += Input.GetAxis ("Horizontal") * playerVelocity; transform.position = playerPosition; **To check taps** private void touchMove() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.position.x < Screen.width/2) { //simulate a left keyboard push } else if (touch.position.x > Screen.width/2) { //simulate a left keyboard push } } }

Input.GetAxisRaw with delete and shift

$
0
0
Hello, I'm trying to get a combination of shift key and Delete key to produce a result in my game, using Input.GetAxisRaw(). I have defined both shift (left and right) and delete as Axes in the Input manager. Axes->Delete Name: Delete Positive Button: delete Gravity: 1000 Dead: 0.001 Sensitivity: 1000 Type: Key or Mouse Button Axis: X axis Joy Num: Get Motion from all Joysticks Other values are blank. In the script code called from Update() I have the following: if (Input.GetAxisRaw (Keys.Delete) != 0) {} Keys.Delete = "Delete" from a Keys class to just eliminate typos. This works fine if I just hit Delete on its own. However, when I hold down shift and hit Delete, the Axis condition is not fired. I verified this with debug breakpoints too. Is anyone else able to create this issue? Could this be as a result of the Unity hot-key for shift+del causing issues when running my game in the editor? Is this a bug potentially? Did I mess something up?

Why doesn't Input.GetAxis("Horizontal") > 0 stop immediately?

$
0
0
I'm having a hard time to understand why after I stop pressing right or left in order to move my sprite, when I release any arrow button it keeps few frames moving when I meant to stop them right away. Any ideas? he is the vanilla moving code: // Update is called once per frame void Update() { if (Input.GetAxis("Horizontal") > 0) { transform.Translate(Vector3.right * speed * Time.deltaTime); transform.eulerAngles = new Vector2(0, 0); } if (Input.GetAxis("Horizontal") < 0) { transform.Translate(Vector3.right * speed * Time.deltaTime); transform.eulerAngles = new Vector2(0, 180); } if (Input.GetAxis("Vertical") > 0) { transform.Translate(Vector3.up * speed * Time.deltaTime); } else if (Input.GetAxis("Vertical") < 0) { transform.Translate(Vector3.down * speed * Time.deltaTime); } }

"Input.GetAxis()" Lagging?

$
0
0
Something weird is going on here. Basically, I'm running a script that changes a variable according to the value returned by Input.GetAxis. Nothing new, really. The problem is that the change in Input.GetAxis's value seems to lag. It takes a fraction of a second for it to catch up with the rest of the game. Here's my code: var moveDirection = 0; var move2 = 0 //for comparison function Update() { moveDirection = Input.GetAxis("Horizontal"); if (GetKeyDown("left")) { move2 = -1 } if (GetKeyDown("right")) { move2 = 1 } } Shouldn't moveDirection and move2 be changing values at the same time? Why isn't this the case?

Problem with animator and GetAxis

$
0
0
Hello fellow developers, I had a problem using GetAxis, maybe I am using it wrong but it doesn't seem to work because it does not listen to my input. . Here is my script: using UnityEngine; using System.Collections; public class SpelerScript : MonoBehaviour { //Get animator private Animator Anim; void Awake(){ Anim = GetComponent(); } void Update () { if (Anim.GetBool("isIdle")) { Debug.Log("isIdle!"); //Hop forwards if (Input.GetAxis("Vertical") > 0){ Debug.Log("Hop forward should start"); Anim.SetBool("isIdle",false); Anim.SetTrigger("hopForward"); } //Hop backwards else if (Input.GetAxis("Vertical") < 0){ Debug.Log("Hop back should start"); Anim.SetBool("isIdle",false); Anim.SetTrigger("hopBack"); } //Hop right else if (Input.GetAxis("Horizontal") > 0){ Debug.Log("Hop right should start"); Anim.SetBool("isIdle",false); Anim.SetTrigger("hopRight"); } //hop left else if (Input.GetAxis("Horizontal") < 0){ Debug.Log("Hop left should start"); Anim.SetBool("isIdle",false); Anim.SetTrigger("hopLeft"); } } } } this happens because the if statement can't acces something Picture of my animator [here][1], every line to one of the 4 animations has it's own parameter, assigned in the script above, they are named hopBack, hopForward, hopRight, hopLeft. The Idle state in the middle has a behaviour which sets isIdle to true. You can view the transitions [here][3] and [here][2]. [1]: http://prntscr.com/7qzd98 [3]: http://prntscr.com/7r4ttw [2]: http://prntscr.com/7r4ug4

Input Axis vertical not defined

$
0
0
Hi I made a new car controller script in Unity 5 public float speed =10.0f; public float reverseSpeed =5.0f; public float turnSpeed =0.6f; private float moveDirection =0.0f; private float turnDirection =0.0f; private Rigidbody rb; // Use this for initialization void Start () { rb= GetComponent(); } // Update is called once per frame void Update () { moveDirection = Input.GetAxis("vertical") * speed ; rb.AddRelativeForce(0,0, moveDirection); } Initiall the console does not show any error and the game mode starts but then the car does not move and the error pops up at the bottom **Input Axis vertical not defined**

Using mouse input to control a helicopter

$
0
0
Hi all, I'm trying to set up a game in which I can control a helicopter using similar controls to what is used in games like Battlefield. I am using the Input.GetAxis (Vertical) for forwards and backwards movement using code such as: forward_force = Input.GetAxis ("Vertical") //mouse x axis sideways_force = Input.GetAxis ("Horizontal") //mouse y rigidbody.AddTorque (transform.right * forward_force); //tilt chopper forwards /back rigidbody.AddForce( transform_forward*forward_force); //drive chopper forward/back Problem is, the mouse values are all over the place, they will read all sorts of values depending on how fast I move the mouse. Then if the mouse is not moved, they return to 0, resulting in no forward momentum Is there a method of somehow keeping the mouse value until the next move of the mouse ? I have also tried Mouse X and Mouse Y, but again, the values are jumpy Ideally, I'm thinking as the chopper tilts forward due to torque , i can set a vector of appropriate force to move it forward based on the local transform rotation or similar, unless anyone can offer a better solution

Input.GetAxis - Based on cursor screen position?

$
0
0
I'm using Input.GetAxis to move a Rigidbody object with the mouse by changing its velocity. This works fine, but I would like the cursor to stay on the Rigidbody. I would like to know if Input.GetAxis("Mouse X") depends on the actual screen position of the cursor - or if this is getting mouse delta in some other, non-screen-dependant way? Thanks!

How can I use both mouse and keyboard to do the same thing? [SOLVED]

$
0
0
Hello! I've just finished the Breakout Game tutorial and I want to move my paddle object with both keyboard and mouse. I want the player to choose which one he/she wants. public float paddleSpeed = 1f; private Vector3 playerPos = new Vector3 (0, -9.9f, 0); // Update is called once per frame void Update () { float xPos = transform.position.x + (Input.GetAxis ("Mouse X") * paddleSpeed); playerPos = new Vector3 (Mathf.Clamp (xPos, -7.5f, 7.5f), -9.9f, 0f); transform.position = playerPos; } } I've discovered how to move with my mouse but how can I add 'Input.GetAxis ("Horizontal")' into the script? And how can I hide my mouse pointer?

Game doesn't recognize X-axis input from XBox 360 controller

$
0
0
I have a problem with the usage of XBox controller in Unity game. I connected the controller to the PC and it works fine, I also managed to use it in the game itself - I'm using "A" button to fire and Start to start the game and they work properly. However the game doesn't recognize the x-axis movement (y-axis would probably have the same problem but we don't use it in our game). I'm not sure if the problem is in the input settings or my code. This is how the Horizontal movement is defined in the game: ![alt text][1] [1]: /storage/temp/55136-horizontalsettings.png This is the code that handles the movement: float x = Input.GetAxis("Horizontal"); Vector3 newPosition = new Vector3(transform.position.x + x*playerXMoveSpeed, 0, 0); newPosition.y = transform.position.y; newPosition.z = 0; transform.position = Vector3.Lerp(transform.position, newPosition, playerXMoveSpeed * Time.deltaTime); var limit = animator.SpriteRenderer.bounds.extents; if (transform.position.x - limit.x < leftBorder) { var capped = transform.position; capped.x = leftBorder + limit.x; transform.position = capped; } else if (transform.position.x + limit.x > rightBorder) { var capped = transform.position; capped.x = rightBorder - limit.x; transform.position = capped; } OnMove(gameObject); All variables are more or less self explanatory, the OnMove is a delegate that just applies the transform to the gameObject in question. The entire code is inside a void method called Move(). That method is called inside an if statement: if ((Input.GetAxis("Horizontal") != 0.0f || Input.GetButtonDown("Horizontal"))) { Move(); } Like I said, the game recognizes the other buttons, but not the x-axis, it doesn't move the character. The Input.GetButtonDown is there just so keyboard input would be supported also (and it works properly). Can you see the problem with this code or settings? Please advise.

Joystick Angle Problem

$
0
0
Hello, I am trying to use a controller's joystick and get the angle the joystick is at. I currently have this code: angle = Mathf.Atan2(Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical")) * Mathf.Rad2Deg; Which works fine until you release the joystick which returns the angle to zero (to be expected). My question is however, how can I save the previous angle and keep it when the joystick is released? Ive tried this: if (stickInput.magnitude > deadZone) { angle = Mathf.Atan2(Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical")) * Mathf.Rad2Deg; } Which works fine until the joystick's angle is negative. (Since the angle is calculated counter clockwise from 0 to 180 then -180 to 0) When it is, every so often(after numerous tests it seems completely random) the angle will become positive when the joystick is released instead of staying negative. For example, I turn the joystick to the left completely. The angle is -90. Sometimes when the joystick is released, the angle will become 90. If anyone knows why this is happening or how to fix it, please let me know. If my explanation didn't make sense, I'll try to reword it. Thanks for the help.

Joystick Angle Problems

$
0
0
Hello, I am trying to use a controller's joystick and get the angle the joystick is at. I currently have this code: angle = Mathf.Atan2(Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical")) * Mathf.Rad2Deg; Which works fine until you release the joystick which returns the angle to zero (to be expected). My question is however, how can I save the previous angle and keep it when the joystick is released? Ive tried this: if (stickInput.magnitude > deadZone) { angle = Mathf.Atan2(Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical")) * Mathf.Rad2Deg; } Which works fine until the joystick's angle is negative. (Since the angle is calculated counter clockwise from 0 to 180 then -180 to 0) When it is, every so often(after numerous tests it seems completely random) the angle will become positive when the joystick is released instead of staying negative. For example, I turn the joystick to the left completely. The angle is -90. Sometimes when the joystick is released, the angle will become 90. If anyone knows why this is happening or how to fix it, please let me know. If my explanation didn't make sense, I'll try to reword it. Thanks for the help.

Input.GetAxis(“Horizontal”) not updating

$
0
0
I'm having trouble with Unity's basic character controlling. After i implemented the crouching in the code below the Input.GetAxis("Horizontal") does not update (while the left control is pressed (crouching), Input.GetAxis("Horizontal") is always set to zero even if left or right arrows are pressed. The reason why this happens is not because of keyboard buffer etc. because horizontal input is working while jumping, which is implemented pretty much the same way the crouching is implemented in the code below. Btw. no root motion is used. Here's the code: void HandleInput(){ currentBaseState = animator.GetCurrentAnimatorStateInfo(0); var deadZone = 0.1f; verticalVelocity = moveVector.y; moveVector = Vector3.zero; // print for testing print(Input.GetAxis("Horizontal")); if (Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone) { yRotation += Input.GetAxis("Horizontal"); animator.SetFloat("Direction", Input.GetAxis("Horizontal")); } if (Input.GetAxis ("Vertical") > deadZone) { speed += 0.1f; moveVector += new Vector3 (0, 0, Input.GetAxis ("Vertical") + speed); } else if(Input.GetAxis ("Vertical") < -deadZone) { if(speed >= 0) speed -= 0.1f; else speed += 0.1f; moveVector += new Vector3 (0, 0, Input.GetAxis ("Vertical") + speed); } else { moveVector += new Vector3(0, 0, Input.GetAxis ("Vertical") + previousSpeed); if(speed > 0) speed -= 0.1f; } animator.SetFloat ("Speed", Input.GetAxis ("Vertical")); totalRotation = yRotation * rotationMultiplier; transform.eulerAngles = new Vector3(0, totalRotation, 0); moveVector = transform.TransformDirection(moveVector); if (moveVector.magnitude > 1) moveVector = Vector3.Normalize(moveVector); Physics.Raycast (gameObject.transform.position, Vector3.down, out hitInfo, 0.5f); if(hitInfo.distance < 0.5f) { if (enableJump) { if (Input.GetButtonDown("Jump")) { animator.SetBool("Jump", true); verticalVelocity = jumpSpeed; skillSlider.value -= 1f; if(skillSlider.value == 0f){ enableJump = false; bunnyImage.gameObject.SetActive(false); skillSlider.gameObject.SetActive(false); } } } } if (Input.GetButtonDown ("Crouch")) { animator.SetBool ("Crouch", true); crouching = true; } if (Input.GetButtonUp("Crouch")) { crouching = false; } if (currentBaseState.fullPathHash == crouchState) { if(!animator.IsInTransition(0)){ if(!crouching) animator.SetBool("Crouch", false); } } if (currentBaseState.fullPathHash == jumpState) { if (!animator.IsInTransition(0)) { animator.SetBool("Jump", false); } } previousSpeed = speed; moveVector = new Vector3(moveVector.x, verticalVelocity, moveVector.z); if (moveVector.y > -terminalVelocity) moveVector = new Vector3(moveVector.x, moveVector.y - gravity * Time.deltaTime, moveVector.z); if (characterController.isGrounded && moveVector.y < -1) moveVector = new Vector3(moveVector.x, -1, moveVector.z); characterController.Move(moveVector * Time.deltaTime); }

Input Snap option not returning 0?

$
0
0
Hi! So, I'm moving my character (2D game) with these 2 lines of coding float move = Input.GetAxis ("Horizontal"); rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y); And it works... But if I press, let's say, the right key for a short moment and then press the left key, the command GetAxis won't return me 0. Instead, it constantly returns the value **move** was when I pressed the left key. I don't know if I'm being clear. It's something like this: Pressing right --> 0.1 Pressing right --> 0.3 Pressing right --> 0.5 Pressing right and left --> **0.5** Pressing right and left --> **0.5** And so on.. According to the Unity Documentation: > *If (snap is) enabled, the axis value will be immediately reset to zero after it receives opposite inputs. Only used when the Type is key / mouse button.* (http://docs.unity3d.com/Manual/class-InputManager.html) And looks like that's not happening, so... I'm lost. Any thoughts?
Viewing all 266 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>