- Home /
Script behaves differently when using a pad
Hi I am making a side scrolling shooter game. I can clamp the player to the bounds of the screen size however the other day I wanted to use my controller (my mad catz street fighter x tekken pad for Xbox 360) to test the game and my script behavior changed.
Using keyboard controls the player cannot leave the screen and if you imagine an invisible border just inside the screen edge this edge acts as a wall, but when I changed the buttons in Edit>Project Settings>Input the player is still bound to the screen but part of the mesh (cube in this case) can leave the screen. Also the player speed changes
I'm not sure why this happens and was wondering if anyone had any clues about this. I was in the mindset that I was just changing the button used to move and nothing else. If it helps here is my code for clamping the player and how I keep them within the screen completely so no part of the player leaves the screen...
Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);
pos.x = Mathf.Clamp01 (pos.x);
pos.y = Mathf.Clamp01 (pos.y);
transform.position = Camera.main.ViewportToWorldPoint(pos);
//Left Side Of The Screen
if (pos.x <=0.1)
{
leftControlEnabled = false;
}
else
{
leftControlEnabled = true;
}
and this is my code for player movement/speed...
//Left Movement
if (leftControlEnabled)
{
player.Translate(Vector3.right * playerSpeed * Input.GetAxis ("leftMove") * Time.deltaTime);
}
Any help is greatly appreciated :). Thank you. P.S I use C#.
Are the values from Input.GetAxis ("left$$anonymous$$ove")
different, e.g. higher, when you switch between control inputs? If the player moves faster a bigger part of the mesh might reach outside of the wall, because you're using player.Translate()
and a position check. $$anonymous$$g. if the player is at 0.5 and you translate them to 0.0 in one frame, then you'll hit the pos.x <= 0.1
check, but you'll also hit this check if you translate from 0.5 to -1.0 in one frame, but the player will have moved further.
Answer by Kebabs · Oct 15, 2013 at 09:56 AM
Thanks for the reply. No the values remain the same. The only thing I change in the input manager is the button used and all other values such as gravity for example stay the same. I change it from A (for "leftMove") to the joypad X axis (D-pad on 360 pad). I don't alter the playerSpeed at all I just change the input to move.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do I set up my players controller script (How do I change the controls used to move and look) 2 Answers
Best use of GetButton 4 Answers
Assign and detect controls for each character to different gamepads and/or mouse and keyboard 0 Answers
iPhone joystick? 0 Answers