Modify Script for iPhone Joystick Controls

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

UnityFun
Posts: 1
Joined: 31 Dec 2012, 07:01

Modify Script for iPhone Joystick Controls

Postby UnityFun » 31 Dec 2012, 17:33

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;
          }
       }
    }
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: Modify Script for iPhone Joystick Controls

Postby ThomasLund » 01 Jan 2013, 20:16

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
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund

Return to “SFS2X C# API”

Who is online

Users browsing this forum: Google [Bot] and 36 guests