Movement in Photon

So what do i have to do to my code to get players to be able to control their own ships?

Appreciate any help i can get.

[code2=javascript]@script RequireComponent (Rigidbody)

// set turning speed variables.
var baseTurnSpeed:float=1;
var maxTurnSpeed:float = 2;
var baseMaxSpeed:float = 10;
var maxSpeed:float = 10;
var maxSpeedPercent:int = 0;
static var warpAllowed:boolean = true;
static var doWarp:boolean = false;
static var speedBoost = 1;
var pitched:float;
var yaw:float;
var roll:float;
var enginePower:float;
var speed:Vector3;
var mag:float;
var warpflash:GameObject;
private var launchLocation:Vector3;
var flashed:boolean = false;

//decide if a player will control this ship.
var playerControlled:boolean=true;
//is the pitch inverted?
var invertVertical:boolean=true;

function SetPlayerControl(control:boolean)
{
playerControlled = control;
}

function Update()
{
updateEngine();
if (playerControlled)
{ //get new axis rotation buttons

pitched = Input.GetAxis("Vertical");
yaw = Input.GetAxis("Horizontal") ;
roll = Input.GetAxis("Roll");
//get speed setting.
if (Input.GetButtonDown("engine 0%"))
maxSpeedPercent = 0;
if (Input.GetButtonDown("engine 10%"))
maxSpeedPercent = 10;
if (Input.GetButtonDown("engine 20%"))
maxSpeedPercent = 20;
if (Input.GetButtonDown("engine 30%"))
maxSpeedPercent = 30;
if (Input.GetButtonDown("engine 40%"))
maxSpeedPercent = 40;
if (Input.GetButtonDown("engine 50%"))
maxSpeedPercent = 50;
if (Input.GetButtonDown("engine 60%"))
maxSpeedPercent = 60;
if (Input.GetButtonDown("engine 70%"))
maxSpeedPercent = 70;
if (Input.GetButtonDown("engine 80%"))
maxSpeedPercent = 80;
if (Input.GetButtonDown("engine 90%"))
maxSpeedPercent = 90;
if (Input.GetButtonDown("engine 100%"))
maxSpeedPercent = 100;

}
//vertical axis is default as inverted, so we will multiply by -1 to switch to none inverted if it's unchecked.
if(!invertVertical)
pitched *= -1;
//perform all rotation commands.
transform.Rotate(pitched * baseTurnSpeed * Time.deltaTime *10,yaw * baseTurnSpeed * Time.deltaTime *10,roll * baseTurnSpeed * Time.deltaTime *10);
if (maxSpeedPercent != 0) {
rigidbody.AddForce(transform.forward * Time.deltaTime * (enginePower * maxSpeedPercent * speedBoost) * 1);
}
if (mag > 2000.0 && flashed == false) {
flashed = true;
dropFlash();
}
if (mag < 2000.0 && flashed) {
flashed = false;
}
if (mag > enginePower * maxSpeedPercent) {
rigidbody.velocity = rigidbody.velocity * 0.99;
}
else if (mag <= enginePower * maxSpeedPercent) {
rigidbody.velocity = rigidbody.velocity * 0.9995;
}
if (Input.GetButtonDown("Warp"))
maxSpeedPercent = 5000000;
if (warpAllowed)
{
warpAllowed = false;
doWarp = true;
}
if (Input.GetButtonDown("DeWarp"))
maxSpeedPercent = 0;
if (warpAllowed)
{
warpAllowed = true;
doWarp = false;
}
}

function updateEngine() {
maxSpeed = GetComponent(shipClass).get_engine_percent() * baseMaxSpeed;
enginePower = GetComponent(shipClass).get_engine_power();
speed = rigidbody.velocity;
mag = rigidbody.velocity.magnitude;
}

function dropFlash() {
launchLocation = Vector3(transform.position.x,transform.position.y,transform.position.z);
var flash:GameObject = Instantiate(warpflash,launchLocation,transform.rotation);
flash.transform.Rotate(Vector3(180,0,0));
flash.velocity = Vector3(0,0,0);

}[/code2]
Sign In or Register to comment.