Friday, April 12, 2013

scripts


so lets start with my job for the past couple of weeks, what i have done is created and fixed scripts that involve temporary editing to the chatacter and the game known as triggers

a basic trigger i made was a timed trigger where a platform disappears 1 second after the object is touched by the PLAYER and only the PLAYER.


var object : GameObject;
function Start() {
var object : GameObject;
   object = GetComponent(GameObject) as GameObject;
}
function OnTriggerEnter (other : Collider) {
 if (other.CompareTag ("Player"))
 print("you touched me");
     Destroy(object,1);
}

next is a more complicated script, this is attached to the character, what it does is basically if the PLAYER is in the air you are allowed to press the key "X" and the players trigger is turned on momentarily and a force is applied downward, similar to marios jump pound from the newer super mario bros games.


#pragma strict
var chMotor : CharacterMotor;
var movement : CharacterMotorMovement;
var trigger : SphereCollider;
var gravity : Vector3;
var isGrounded : boolean;
function Start () {
movement = CharacterMotorMovement();
chMotor = GetComponent(CharacterMotor);
trigger = GetComponent(SphereCollider) as SphereCollider;
}
 function Update () {
        if(Input.GetKey("x")/* || Input.GetKey("s")*/ && transform.GetComponent(CharacterController).isGrounded == false){

chMotor.movement.gravity = 100000;
 print("get it down");
trigger.isTrigger = true;
        }
        else if (transform.GetComponent(CharacterController).isGrounded == true)
        {
        chMotor.movement.gravity = 20;
         print("grounded");// void;
         trigger.isTrigger = false;
         }  
}

with that there has to be an individual script that allows the trigger that is momentarily turned on to destroy specific objects or obstacles in the way.

//var object = GetComponent(GameObject) as GameObject;
//var trigger = GetComponent(SphereCollider) as SphereCollider;

var object : GameObject;
var trigger : SphereCollider;

//var player = GameObject.Find("guy");
function Start() {
var object : GameObject;
   object = GetComponent(GameObject) as GameObject;
   var trigger : SphereCollider;
trigger = GetComponent(SphereCollider) as SphereCollider;
}
function OnTriggerEnter (other : Collider) {

 if (other.CompareTag ("Player") && trigger.isTrigger == true)
 {
 print("you touched me");
     Destroy(object);
     }
}

this consists of the triggers that will aid to super powers in the game, another team member should be posting the the rock throw power soon.

No comments:

Post a Comment