Hey guys I’m working on a little project for class and what I’m trying to do is recreate a control scheme like NOVA or other iphone fps games…I want to slide one finger anywhere to look around and have a single joystick for movement. I’ve got it to work, but the finger controlling the movement joystick is also moving the camera. Is there a way to separate these out? My character has a character controller, a mouselook script, and a movement script I modified to work with one joystick.
@script RequireComponent( CharacterController )
var moveJoystick : Joystick;
var forwardSpeed : float = 4;
var backwardSpeed : float = 1;
var sidestepSpeed : float = 1;
var jumpSpeed : float = 8;
var inAirMultiplier : float = 0.25; // Limiter for ground speed while jumping
private var thisTransform : Transform;
private var character : CharacterController;
private var velocity : Vector3; // Used for continuing momentum while in air
function Start()
{
// Cache component lookup at startup instead of doing this every frame
thisTransform = GetComponent( Transform );
character = GetComponent( CharacterController );
}
function OnEndGame()
{
// Disable joystick when the game ends
moveJoystick.Disable();
// Don't allow any more control changes when the game ends
this.enabled = false;
}
function Update()
{
var movement = thisTransform.TransformDirection( Vector3( moveJoystick.position.x, 0, moveJoystick.position.y ) );
// We only want horizontal movement
movement.y = 0;
movement.Normalize();
// Apply movement from move joystick
var absJoyPos = Vector2( Mathf.Abs( moveJoystick.position.x ), Mathf.Abs( moveJoystick.position.y ) );
if ( absJoyPos.y > absJoyPos.x )
{
if ( moveJoystick.position.y > 0 )
movement *= forwardSpeed * absJoyPos.y;
else
{
movement *= backwardSpeed * absJoyPos.y;
}
}
else
{
movement *= sidestepSpeed * absJoyPos.x;
// Let's move the camera a bit, so the character isn't stuck under our thumb
}
// Check for jump
if ( character.isGrounded )
{
if ( moveJoystick.tapCount == 2 )
{
// Apply the current movement to launch velocity
velocity = character.velocity;
velocity.y = jumpSpeed;
}
}
else
{
// Apply gravity to our velocity to diminish it over time
velocity.y += Physics.gravity.y * Time.deltaTime;
// Adjust additional movement while in-air
movement.x *= inAirMultiplier;
movement.z *= inAirMultiplier;
}
movement += velocity;
movement += Physics.gravity;
movement *= Time.deltaTime;
// Actually move the character
character.Move( movement );
if ( character.isGrounded ) {
// Remove any persistent velocity after landing
velocity = Vector3.zero;
}
}