Playercharacter

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

// DGH1 // Oisin Bourke var target: Transform; var mySphere : GameObject; // The following variables define the speed,

gravity and direction of the charac ter // The charController adds a character controller variable which can be referenc ed directly to the controller in my scene. private var walkSpeed : float = 1.0; private var gravity = 100.0; private var moveDirection : Vector3 = Vector3.zero; private var charController : CharacterController; // The Strength variable indicates force of movement when colliding with rigidbo dies. private var strength = 4.0; // The Start() function runs before any other function, in this case getting the charcontroller and setting the animation mode. function Start (){ charController = GetComponent(CharacterController); animation.wrapMode = WrapMode.Loop; } // The Update() function runs every frame function Update() { // The if-statement here relates to cloning my fireball and instantiating it inf ront of the player if(Input.GetButtonUp("Fire1")) { var obj : GameObject = Instantiate(mySphere, transform.position+ Vector3(0.0,3,5.0), transform.rotation); } // This if-statement destroys my fireball clone if(Input.GetButtonUp("remove")) { Destroy(GameObject.Find("Sphere1(Clone)")); } // This if-statement checks if my character is touching the ground if(charController.isGrounded == true) { // This if-statement checks for vertical input of greater than 0.1 (in case of a naloge input device), if true it runs the animation. if(Input.GetAxis("Vertical") > .1) { animation.CrossFade("run"); walkspeed = 4; } // if the above is NOT true then the "else" statement (idle animation) is execut ed. else { animation.CrossFade("idle"); } //????????????????????????????? if(Input.GetAxis("Vertical") < -.1) { animation["walk"].speed = -1; animation.CrossFade("walk");

walkSpeed = 1; } if(Input.GetAxis("Horizontal") && !Input.GetAxis("Vertical")) { animation.CrossFade("walk"); } // Our character turns on an axis via the Input.GetAxis function, to do this in increments we use a Euler. // The operater in the statement below (+=) adds what is on it's left to what is on it's right transform.eulerAngles.y += Input.GetAxis("Horizontal"); //These two lines move the character in the needed direction moveDirection = Vector3(0,0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); } // This line causes my character to go downwards at an accelerating rate when fa lling. // Gravity multiplied by the time, then subtracted from the moveDirections Y vec tor. moveDirection.y -= gravity * Time.deltaTime; charController.Move(moveDirection*walkSpeed); } // The OnControllerColliderHit( ) function is called when collision is detected and hold the object you collided with function OnControllerColliderHit (hit : ControllerColliderHit) { // These variables set the movement direction of the collided object var body : Rigidbody = hit.collider.attachedRigidbody; var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z); // this next statement applies speed to the collided object body.velocity = pushDir*strength*10; }

You might also like