Hi,
I have a FPS game, that includes a FPS Ctrl and a Spaceship.
My problem is that the character and the ship move together on the scene, and I need the FPS ctrl to be able to enter the Spaceship so it can be controlled. Also, this script is best put into the FPS ctrl or the Spaceship? I’m using I’m sorry if this is some repost, but I haven’t found something similar that helped. Here’s the code I have on the Spaceship so far…
I’m very noob with coding yet…
thanks btw.
var camera1 : Camera;
var camera2 : Camera;
var turnspeed = 5.0;
var speed = 5.0;
private var trueSpeed = 0.0;
var strafeSpeed = 5.0;
var InShip : Transform;
var Player : Transform;
var PlayerIn = false;
var ExitPoint = Transform;
var CanChange = true;
function Update () {
var roll = Input.GetAxis("Roll");
var pitch = Input.GetAxis("Pitch");
var yaw = Input.GetAxis("Yaw");
var strafe = Vector3(Input.GetAxis("Horizontal")*strafeSpeed*Time.deltaTime, Input.GetAxis("Vertical")*strafeSpeed*Time.deltaTime, 0);
var power = Input.GetAxis("Power");
Player = GameObject.FindWithTag("Player").transform;
if(PlayerIn == true)
{
Player.transform.position.y = InShip.transform.position.y;
Player.transform.position.z = InShip.transform.position.z;
Player.transform.position.x = InShip.transform.position.x;
}
else
{
}
if(Input.GetKey(KeyCode.W)&& PlayerIn == true)
{
rigidbody.velocity = transform.forward * speed *Input.GetAxis("car");
rigidbody.velocity.y = Input.GetAxis("root");
}
//Truespeed controls
if (trueSpeed < 3000 && trueSpeed > -3000)
{
trueSpeed += power;
}
if (trueSpeed > 3000)
{
trueSpeed = 0;
}
if (trueSpeed < -3000)
{
trueSpeed = 0;
}
if (Input.GetKey("c"))
{
trueSpeed = 0;
currentVelocity = rigidbody.velocity;
oppositeForce = -currentVelocity;
rigidbody.AddRelativeForce(oppositeForce.x, oppositeForce.y, oppositeForce.z);
print(trueSpeed);
}
rigidbody.AddRelativeTorque(pitch*turnspeed*Time.deltaTime, yaw*turnspeed*Time.deltaTime, roll*turnspeed*Time.deltaTime);
rigidbody.AddRelativeForce(0,0,trueSpeed*speed*Time.deltaTime);
rigidbody.AddRelativeForce(strafe);
}
function OnTriggerEnter(other : Collider)
{
if(GameObject.FindWithTag("Player")) && (GameObject.FindWithTag ==("Spaceship")
{
camera1.enabled = false;
camera2.enabled = true;
}
}