- Home /
Iphone joystick where player touches
I know this might have been discussed elsewhere but honeslty, i couldn't find a thing!
All i want is to make the joystick appear wherever the player touches (like i.e. in Predators game ).
I am using the built-in joystick script. I tried changing its position on update but although the stick appears where i touch, the controls do not correspond to that position.
The following is the code i added to the Joystick.js script inside Update ( tried to make it work both with touch and mouse ).
//Position joystick wherever clicked/touched
if ( Application.platform != RuntimePlatform.IPhonePlayer ){
if(Input.GetMouseButtonDown(0)){
var screenPos=Camera.main.ScreenToViewportPoint(Input.mousePosition);
transform.position.x=Mathf.Abs(screenPos.x);
transform.position.y=Mathf.Abs(screenPos.y);
}
}
else {
if ( Input.touchCount > 0 ){
screenPos = Camera.main.ScreenToViewportPoint(Input.GetTouch(0).position);
transform.position.x=Mathf.Abs(screenPos.x);
transform.position.y=Mathf.Abs(screenPos.y);
}
}
Any ideas/scripts/resources i should check?
If anyone done this before PLEASE answer.
Thank you!!!
I unfortunately don't have time to get you a good answer at the moment, but this should improve your code: http://unity3d.com/support/documentation/$$anonymous$$anual/Platform%20Dependent%20Compilation.html
Your answer
Follow this Question
Related Questions
Joystick / Button 3 Answers
Joystick C# change touch zone? 0 Answers
Pinball Joystick 0 Answers
ITouch multi touch with joystick problem 0 Answers
Multiple touch iPhone Buttons 0 Answers