Hi,
I’m trying to make an iOS 3D game. I’ve just got into programming so I’m still not familiar with, well, alot.
I want my player to move only on x axis (up or down) when I swipe my finger across it, and only on y (up or down) when I swipe across y.
So far I’ve managed to lock movement to x only (least I think so as it works in test mode), but when I try to write the code for y axis movement, visual studio gives an error for …GetAxis(0, (“Vertical”)));
CS1503 Argument 1: cannot convert from ‘int’ to 'char’8.
Can anyone help please?
Also, player needs to move forward automatically, hence, transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.World); . - this part works fine.
Thank you for your time in advance.
void Start ()
{
mybody = this.GetComponent < Rigidbody> ();
}
void FixedUpdate()
{
transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.World);
if (CnInputManager.GetAxis("Horizontal") < 0)
{
moveDirection = new Vector2(CnInputManager.GetAxis("Horizontal"), 0);
moveDirection = transform.TransformDirection(-moveDirection);
moveDirection = -moveDirection * speed * moveForce * Time.deltaTime;
mybody.AddForce(moveForce * -moveDirection);
}
else if (CnInputManager.GetAxis("Horizontal") > 0)
{
moveDirection = new Vector2(CnInputManager.GetAxis("Horizontal"), 0);
moveDirection = transform.TransformDirection(-moveDirection);
moveDirection = -moveDirection * speed * moveForce * Time.deltaTime;
mybody.AddForce(moveForce * -moveDirection);
}
else if (CnInputManager.GetAxis("Vertical") < 0)
{
moveDirection = new Vector2(CnInputManager.GetAxis(0, ("Vertical")));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection = moveDirection * speed * moveForce * Time.deltaTime;
mybody.AddForce(moveForce * moveDirection);
}
else if (CnInputManager.GetAxis("Vertical") < 0)
{
moveDirection = new Vector2(CnInputManager.GetAxis(0, ("Vertical")));
moveDirection = transform.TransformDirection(-moveDirection);
moveDirection = -moveDirection * speed * moveForce * Time.deltaTime;
mybody.AddForce(moveForce * -moveDirection);
}
}
}