Page 1 of 1

Modify Script for iPhone Joystick Controls

Posted: 31 Dec 2012, 17:33
by UnityFun
The following script is provided by SmartFox to control the movement of a player using the keyboard:

http://docs2x.smartfoxserver.com/Exampl ... t-movement

Can this script be modified to allow player movement using the traditional ‘joystick controls’ or left (move player forward and backward) and right (look up and down) thumb presses on an iPhone instead of keyboard presses as originally setup in the script?

Thank you in advance

SCRIPT (Player Controller using the Keyboard Convert to iPhone Left and Right Joystick Controls)

Code: Select all

[code]using UnityEngine;
    using System.Collections;
   
    public class PlayerController : MonoBehaviour {
       
       public float forwardSpeed = 10;
       public float backwardSpeed = 8;
       public float rotationSpeed = 40;
       
       // Dirty flag for checking if movement was made or not
       public bool MovementDirty {get; set;}
   
       void Start() {
          MovementDirty = false;
       }
       
       void Update () {
          // Forward/backward makes player model move
          float translation = Input.GetAxis("Vertical");
          if (translation != 0) {
             this.transform.Translate(0, 0, translation * Time.deltaTime * forwardSpeed);
             MovementDirty = true;
          }
       
          // Left/right makes player model rotate around own axis
          float rotation = Input.GetAxis("Horizontal");
          if (rotation != 0) {
             this.transform.Rotate(Vector3.up, rotation * Time.deltaTime * rotationSpeed);
             MovementDirty = true;
          }
       }
    }

Re: Modify Script for iPhone Joystick Controls

Posted: 01 Jan 2013, 20:16
by ThomasLund
Definitely - but you will have to do the coding yourself. Its not really SFS related, but purely a Unity thing.

Read about Unity input model here: http://docs.unity3d.com/Documentation/Manual/Input.html