Hello Unity3D.I have a problem with my GetAxis.The problem is I want my GetAxis to act as a button and when i move my joystick to left or right its really quick and it makes my character looks like it shuttering.I don’t want that.What i want is for the character to move 1 pace or take one step depending if i move the joystick to the left or right.If anyone knows how i can do this.Can you please tell me how?
Heres what i got so far
var Characters : GameObject; // Array of Weapons
var selection : int = 0;
var OkButtonP1 : String = “Accept_P1”;
var OkButtonP2 : String = “Accept_P2”;
var Player1Ready : boolean = false;
var Player2Ready : boolean = false;
var playerMovement : float = 0;
var smooth : float =0;
var speed : float =0;
var amount : float =0;
var gravity : float = 0;
function Start () {
for(var obj:GameObject in Characters)
{
obj.SetActive(false);
Characters[selection].SetActive(true);
}
}
function Update (){
if (Input.GetAxis("Horizontal1"))
{
transform.localPosition.x += playerMovement * smooth * speed * gravity * Input.GetAxisRaw("Horizontal1");
}
if (Input.GetAxis("Depth1"))
{
transform.localPosition.z += playerMovement * Input.GetAxis("Depth1") * Time.deltaTime;
}
if(Input.GetKeyDown("a")||Input.GetAxisRaw("Horizontal2") == 1){
{
Characters[selection].SetActive (false);
selection++;
if (selection >= Characters.length)
selection = 0;
Characters[selection].SetActive (true);
}
}
if(Input.GetKeyDown("d")||Input.GetAxisRaw("Horizontal2") == -1){
Characters[selection].SetActive(false);
selection--;
if (selection < 0)
selection = Characters.length-1;
Characters[selection].SetActive (true);
}
if (Input.GetButtonDown(OkButtonP1)&& Player1Ready == false) {
Player1Ready = true;
}
if (Input.GetButtonDown(OkButtonP2)&& Player2Ready == false) {
Player2Ready = true;
}
if (Input.GetButtonDown(OkButtonP1)&&(Player1Ready == true && Player2Ready == true))
{
PlayerPrefs.SetInt ("PreferedModel",selection);{
PlayerPrefs.SetInt ("PreferedModel2",selection);{
Application.LoadLevel("God N Angels Waterfall Shore");
}
}
}
}
short code for getting something to only update every now and again - using dummy variables/functions for storing the direction, checking the direction and moving in it
public float stepTime;
private float nextStep;
void Update()
{
if (Time.time > nextStep)
{
nextStep = Time.time + stepTime;
direction = CheckTheControlsForDirection();
}
moveInDirection(direction);
}
I Love You! Thank you i have been stuck on this for days =D