so currently I am working on Unity iPhone and have recently done the penelope tutorial
upon finishing the tutorial I wanted to start working on a top down space shooter much like EV Nova, Now the only problem is that I want to slightly adjust a movement script I had written.
You see my movement script will turn and face the player in the direction that the JoyStick is point and start moving the player in that direction.
I need my script to only turn the player when the joystick is moved left or right and to only move the player forward when the joystick is moved forward and to stop the player when the joystick is moved backwards.
Another nice effect could be if the person playing the game move the joystick forward the player will move forward but not stop moving forward until the joystick is pulled backwards kinda to simulate how something would fly in space.
I’m very new to Unity Coding
Thanks
here is the original script
Any suggestions are appreciated
@script RequireComponent( CharacterController )
var moveJoystick : Joystick;
var cameraTransform : Transform;
var speed : float = 6;
private var thisTransform : Transform;
private var character : CharacterController;
function Start(){
thisTransform = GetComponent( Transform );
character = GetComponent( CharacterController );
}
function FaceMovementDirection(){
var horizontalVelocity : Vector3 = character.velocity;
horizontalVelocity.y = 0;
if ( horizontalVelocity.magnitude > 0.1)
thisTransform.forward = horizontalVelocity.normalized;
}
function Update(){
var movement = cameraTransform.TransformDirection( Vector3(
moveJoystick.position.x, 0, moveJoystick.position.y ) );
movement.y =0;
movement.Normalize();
var absJoyPos = Vector2( Mathf.Abs( moveJoystick.position.x ),
Mathf.Abs( moveJoystick.position.y ) );
movement *= speed * ( ( absJoyPos.x > absJoyPos.y ) ? absJoyPos.x : absJoyPos.y );
movement *= Time.deltaTime;
// Actually move the character
movement += Physics.gravity;
character.Move( movement );
FaceMovementDirection();
}