|
Java Code - Movement with Rotate
[Back]
Code:
#pragma strict
var speed : float = 10; //Variables
var jump: boolean = true; //Check if the player can jump
var jumpspeed : float = 8; //Check how high the player can jump
function Update () {
if (Input.GetButton ("w"))
{
transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
}
if (Input.GetButton ("s"))
{
transform.Translate(Vector3(0,0,-speed) * Time.deltaTime);
}
if (Input.GetButton ("a"))
{
transform.Rotate(Vector3(0,-100,0) * Time.deltaTime);
}
if (Input.GetButton ("d"))
{
transform.Rotate(Vector3(0,100,0) * Time.deltaTime);
}
if (Input.GetKeyDown ("space"))
{
if (jump == true) {
rigidbody.velocity.y = jumpspeed;
jump = false;
}
}
}
function OnCollisionEnter(other : Collision)
{
if(other.gameObject.tag == "Water") {
Application.LoadLevel(Application.loadedLevel); //Restart Level
Destroy(gameObject); //Destroy Player
}
if(other.gameObject.tag == "Ground") {
jump = true; //Set jump to 0
}
}
var speed : float = 10; //Variables
var jump: boolean = true; //Check if the player can jump
var jumpspeed : float = 8; //Check how high the player can jump
function Update () {
if (Input.GetButton ("w"))
{
transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
}
if (Input.GetButton ("s"))
{
transform.Translate(Vector3(0,0,-speed) * Time.deltaTime);
}
if (Input.GetButton ("a"))
{
transform.Rotate(Vector3(0,-100,0) * Time.deltaTime);
}
if (Input.GetButton ("d"))
{
transform.Rotate(Vector3(0,100,0) * Time.deltaTime);
}
if (Input.GetKeyDown ("space"))
{
if (jump == true) {
rigidbody.velocity.y = jumpspeed;
jump = false;
}
}
}
function OnCollisionEnter(other : Collision)
{
if(other.gameObject.tag == "Water") {
Application.LoadLevel(Application.loadedLevel); //Restart Level
Destroy(gameObject); //Destroy Player
}
if(other.gameObject.tag == "Ground") {
jump = true; //Set jump to 0
}
}