- Home /
iOS controls
How can I make my ball moving on the touch screen? I want to make a round joystick. I've used the following script:
function Update () {
if (Input.GetKey ("up")) {
rigidbody.AddForce (0, 0, 7);
}
if (Input.GetKey ("down")) {
rigidbody.AddForce (0, 0, -7);
}
if (Input.GetKey ("left")) {
rigidbody.AddForce (-7, 0, 0);
}
if (Input.GetKey ("right")) {
rigidbody.AddForce (7, 0, 0);
}
}
i would look at the iOS example that unity has, penelope. it has a round joystick.
from memory, the Penelope Tutorial is in unity's JavaScript =]
i think their is a tool that can convert it to java, I'm not a 100% percent on that though. joysticks though i haven't done yet as i don't need one so i can't really help.
I just checked and confirmed that the Penelope Tutorial is in js, but you'll need Unity Remote to test it (which means a paid apple developer licence and provisioning). You may be able to go all the way through and run in a simulator (free apple dev licence), you'll just have to try it out and see.
Answer by AlucardJay · Jul 27, 2012 at 11:33 PM
You need to look into the Input states for iOS, using touch is a bit different to mouse and keyboard :
http://docs.unity3d.com/Documentation/ScriptReference/Input-touches.html
http://docs.unity3d.com/Documentation/ScriptReference/Touch.html
http://docs.unity3d.com/Documentation/ScriptReference/TouchPhase.html
Also look at reptilebeats Penelope link =]
Here is an example of reading different Touch States (scroll down to my answer) : http://forum.unity3d.com/threads/142758-Moving-objects-with-your-finger
An example on rotating with Touch Input : http://answers.unity3d.com/questions/289055/rotate-on-drag-for-ios.html
And when the silly spammers leave UnifyCommunity alone, and it gets fixed, check this script. It's what taught me about Touch Input : http://unifycommunity.com/wiki/index.php?title=Tap_to_Move_Drag_to_Look_iPhone
Your answer
Follow this Question
Related Questions
Player movement relative to the camera 4 Answers
Mobile controls need help writing script for 2d game? 0 Answers
Accelometer controls for iOS and android 2 Answers
Question about IOS controls 0 Answers
Simultaneous Touch Drag Controls 0 Answers