Welcome!

Welcome to our community forums, full of great people, ideas and excitement. Please register if you would like to take part.

This is extra text with a test link..

Register Now

Announcement

Collapse
No announcement yet.

Spade Script - Trey Bochat's Character

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spade Script - Trey Bochat's Character

    private var isControllable : boolean;
    private var jumping : boolean;
    private var jumpingReachedApex : boolean;
    private var verticalSpeed : float;
    private var collisionFlags : CollisionFlags;
    private var moveSpeed : float = 0.0;
    private var lastJumpTime : float = -1.0;
    private var lastJumpButtonTime : float = -10.0;
    private var jumpRepeatTime : float = 0.05;
    private var jumpTimeout : float = 0.15;
    private var groundedTimeout : float = 0.25;
    var canJump : boolean = true;
    var jumpHeight = 0.5;
    private var inAirVelocity = Vector3.zero;

    private var spadeCharacter : GameObject;
    private var speed : float = 0.1;
    var jumpSpeed = 8.0;

    var gravity : int = 20;

    private var moveDirection = Vector3.zero;

    var idling : boolean;
    var isRunning : boolean;

    function Awake ()
    {
    spadeCharacter = GameObject.Find("SpadeCharacter");
    }

    function Start () {
    //animation["knight_attack"].layer=1;
    spadeCharacter.animation["Walk"].layer=0;
    spadeCharacter.animation["IdleSpade"].layer=0;
    spadeCharacter.animation["JumpSpade"].layer=1;
    spadeCharacter.animation["Crouch"].layer=0;
    spadeCharacter.animation["StrafeLeft"].layer=0;
    spadeCharacter.animation["StrafeRight"].layer=0;

    }

    function Update () {
    if(Input.GetAxis("Horizontal")<0){
    //Debug.Log("horizontal is working");
    spadeCharacter.animation.CrossFade("StrafeLeft", 0.2);
    }

    if(Input.GetAxis("Horizontal")>0){
    //Debug.Log("horizontal is working");
    spadeCharacter.animation.CrossFade("StrafeRight", 0.2);
    }


    if(Input.GetAxis("Vertical")){
    if (isRunning){
    //Debug.Log(isRunning);
    spadeCharacter.animation.CrossFade("Run", 0.2);
    }else{
    spadeCharacter.animation.CrossFade("Walk", 0.2);
    }
    }
    //if (Input.GetKey (KeyCode.LeftControl) || Input.GetKey (KeyCode.RightControl));
    //spadeCharacter.animation.CrossFade ("Crouch", 0.2);


    if(Input.GetAxis("Fire1")){
    //Debug.Log("Fire1 is working");
    //spadeCharacter.animation.CrossFade("knight_attack" , 0.1);
    }

    if((Mathf.Abs(Input.GetAxis("Horizontal"))<=0.2)&& (Mathf.Abs(Input.GetAxis("Vertical"))<=0.2)){
    idling = true;
    spadeCharacter.animation.CrossFade("IdleSpade", 0.2);
    }else{
    idling = false;
    }

    if (Input.GetKey(KeyCode.LeftShift)){
    isRunning = true;
    speed = 6;
    }else{
    isRunning = false;
    speed = 1.5;
    }

    if (Input.GetButtonDown ("Jump"))
    {
    spadeCharacter.animation.CrossFade("JumpSpade", 0.2);
    lastJumpButtonTime = Time.time;
    }

    ApplyGravity ();
    ApplyJumping();

    var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0) + inAirVelocity;
    movement *= Time.deltaTime;
    }

    function FixedUpdate()
    {

    var controller :CharacterController = GetComponent(CharacterController);

    if(controller.isGrounded)
    {
    moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
    Input.GetAxis("Vertical"));
    moveDirection = transform.TransformDirection(moveDirection);
    moveDirection *= speed;


    }
    if (Input.GetButton ("Fire1"))
    {
    spadeCharacter.animation.CrossFade("Crouch", 0.2);
    }

    if (!idling){
    var rotateY = (Input.GetAxis("Mouse X") * 200) * Time.deltaTime;
    controller.transform.Rotate(0,rotateY, 0);

    }
    moveDirection.y -= gravity * Time.deltaTime;
    controller.Move(moveDirection * Time.deltaTime);
    }

    //New Stuff
    function ApplyJumping ()
    {
    // Prevent jumping too fast after each other
    if (lastJumpTime + jumpRepeatTime > Time.time)
    return;

    if (IsGrounded()) {
    // Jump
    // - Only when pressing the button down
    // - With a timeout so you can press the button slightly before landing
    if (canJump && Time.time < lastJumpButtonTime + jumpTimeout) {
    verticalSpeed = CalculateJumpVerticalSpeed (jumpHeight);
    SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
    }
    }
    }

    function ApplyGravity ()
    {
    if (isControllable) // don't move player at all if not controllable.
    {
    // Apply gravity
    var jumpButton = Input.GetButton("Jump");


    // When we reach the apex of the jump we send out a message
    if (jumping && !jumpingReachedApex && verticalSpeed <= 0.0)
    {
    jumpingReachedApex = true;
    SendMessage("DidJumpReachApex", SendMessageOptions.DontRequireReceiver);
    }

    if (IsGrounded ())
    verticalSpeed = 0.0;
    else
    verticalSpeed -= gravity * Time.deltaTime;
    }
    }

    function CalculateJumpVerticalSpeed (targetJumpHeight : float)
    {
    // From the jump height and gravity we deduce the upwards speed
    // for the character to reach at the apex.
    return Mathf.Sqrt(2 * targetJumpHeight * gravity);
    }

    function DidJump ()
    {
    jumping = true;
    jumpingReachedApex = false;
    lastJumpTime = Time.time;
    lastJumpStartHeight = transform.position.y;
    lastJumpButtonTime = -10;

    _characterState = CharacterState.Jumping;
    }

    function GetSpeed () {
    return moveSpeed;
    }

    function IsJumping () {
    return jumping;
    }

    function IsGrounded () {
    return (collisionFlags & CollisionFlags.CollidedBelow) != 0;
    }
Working...
X