- Home /
How can I define Android or iOS inputs?
instead of Input.GetAxis("Vertical")*moveVec; what should I use for android? and also for Input.GetAxis("Horizontal") please let me know.
I want to use a simple touch on screen for moving forward. and also want to use mobile's motion to turn left and right.
If any better option then this, then also please let me know.
Thanks in advance.
Answer by hirenkacha · Apr 05, 2012 at 07:46 AM
I have got the solution for my game, i am using this code to move forward when touched the screen and stop when released the screen.
if(Input.GetTouch(0).phase==TouchPhase.Stationary)
{
transform = moveVector * Input.touchCount;
}
else
{
transform = moveVector * 0;
}
Thanx for replying and giving me an idea.
Answer by SirGive · Apr 04, 2012 at 06:11 PM
You have to either calculate touch offsets using a delta position or use an onscreen joystick. You also have to catch the device's acelorometer or gyro to detect turning motion. Here is a pretty good example for detecting touch.
thanx.. it really helpd me.. now m looking forward for turning motion.
if any one need accelerometer comment here... i will post it..
I do, are you still offering your help @hirenkacha ?
Answer by hirenkacha · Jun 05, 2012 at 04:16 AM
If you want your car to move according to device tilt, use this
FrontLeftWheel.steerAngle = 20 * Input.acceleration.y; /* you can use any number instead of 20 for sensitivity. FrontLeftwheel is the wheel collider attached to front wheels. .y is for landscape orientation.
FrontRightWheel.steerAngle = 20 * Input.acceleration.y;