GetSpeed() public method

public GetSpeed ( ) : float
return float
コード例 #1
0
    void OnControllerColliderHit(ControllerColliderHit hit)
    {
        Rigidbody body = hit.collider.attachedRigidbody;

        // no rigidbody
        if (body == null || body.isKinematic)
        {
            return;
        }
        // Ignore pushing those rigidbodies
        int bodyLayerMask = 1 << body.gameObject.layer;

        if ((bodyLayerMask & pushLayers.value) == 0)
        {
            return;
        }

        // We dont want to push objects below us
        if (hit.moveDirection.y < -0.3)
        {
            return;
        }

        // Calculate push direction from move direction, we only push objects to the sides
        // never up and down
        Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);

        // push with move speed but never more than walkspeed
        body.velocity = pushDir * pushPower * Mathf.Min(controller.GetSpeed(), controller.walkSpeed);
    }
コード例 #2
0
    public virtual void Update()
    {
        ThirdPersonController playerController = (ThirdPersonController)this.GetComponent(typeof(ThirdPersonController));
        float currentSpeed = playerController.GetSpeed();

        if (currentSpeed > playerController.walkSpeed)
        {
            this.anim.CrossFade("run");
            this.anim.Blend("jumpland", 0);
        }
        else
        {
            if (currentSpeed > 0.1f)
            {
                this.anim.CrossFade("walk");
                this.anim.Blend("jumpland", 0);
            }
            else
            {
                this.anim.Blend("walk", 0f, 0.3f);
                this.anim.Blend("run", 0f, 0.3f);
                this.anim.Blend("run", 0f, 0.3f);
            }
        }
        this.anim["run"].normalizedSpeed  = this.runSpeedScale;
        this.anim["walk"].normalizedSpeed = this.walkSpeedScale;
        if (playerController.IsJumping())
        {
            if (playerController.IsControlledDescent())
            {
                this.anim.CrossFade("jetpackjump", 0.2f);
            }
            else
            {
                if (playerController.HasJumpReachedApex())
                {
                    this.anim.CrossFade("jumpfall", 0.2f);
                }
                else
                {
                    this.anim.CrossFade("jump", 0.2f);
                }
            }
        }
        else
        {
            if (!playerController.IsGroundedWithTimeout())
            {
                this.anim.CrossFade("ledgefall", 0.2f);
            }
            else
            {
                this.anim.Blend("ledgefall", 0f, 0.2f);
            }
        }
    }
コード例 #3
0
    void LateUpdate()
    {
        x += Input.GetAxis("Mouse X") * mouseXSpeedMod;
        y += Input.GetAxis("Mouse Y") * mouseYSpeedMod;
        y  = ClampAngle(y, -15, 45);
        Quaternion rotation = Quaternion.Euler(y, x, 0);

        desireDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * 10f * Mathf.Abs(desireDistance);
        desireDistance  = Mathf.Clamp(desireDistance, MinViewDistance, MaxViewDistance);
        Vector3 position = CameraTarget.position - (rotation * Vector3.forward * desireDistance);

        position = CameraTarget.position - (rotation * Vector3.forward * desireDistance + new Vector3(0, -3.0f, 0));

        transform.position = position;
        transform.rotation = rotation;

        if (controller.GetSpeed() > 0.1f)
        {
            CameraTarget.rotation = Quaternion.Lerp(CameraTarget.rotation, Quaternion.Euler(0.0f, rotation.eulerAngles.y, 0.0f), Time.time * 0.02f);
        }
    }
コード例 #4
0
private void GroundedAnimations()
{
    //blend off any residual animations
    animationGameObject.animation.Blend("fall", 0.0f, 0.1f);
    animationGameObject.animation.Blend("jump", 0.0f, 0.1f);
    animationGameObject.animation.Blend("fly", 0.0f, 0.1f);
    animationGameObject.animation.Blend("elevate", 0.0f, 0.1f);
    animationGameObject.animation.Blend("lower", 0.0f, 0.1f);

    //Fade in Run
    if (characterController.GetSpeed() >= (characterController.GetRunSpeed() - 1))
    {
        animationGameObject.animation.CrossFade("run");
		currentStatus = AnimationStatus.Run;

        //fade out walk
        animationGameObject.animation.Blend("walk", 0.0f, 0.3f);
    }

    // Fade in walk
    else if (characterController.GetSpeed() > 0.1f)
    {

        if (characterController.AreMovingKeysDown())
        {
            animationGameObject.animation.CrossFade("walk");
				currentStatus = AnimationStatus.Walk;
        }
        else
        {
            animationGameObject.animation.Blend("walk", 0.0f, 0.1f);
        }

        // We fade out jumpland realy quick otherwise we get sliding feet
        animationGameObject.animation.Blend("run", 0.0f, 0.3f);



    }

    // Fade out walk and run so just idle remains
    else
    {
        animationGameObject.animation.Blend("walk", 0.0f, 0.3f);
			currentStatus = AnimationStatus.Idle;
       // animationGameObject.animation.Blend("run", 0.0f, 0.3f);
    }

    
    animationGameObject.animation["run"].normalizedSpeed = runSpeedScale;
    animationGameObject.animation["walk"].normalizedSpeed = walkSpeedScale;

    //is Character Jumping
    if (characterController.IsJumping())
    {


        if (!characterController.HasJumpReachedApex() && characterController.IsJumping())
        {
			animationGameObject.animation.CrossFade("jump", 0.2f);
            animationGameObject.animation.Blend("fall", 0.0f, 0.3f);
        }

        else
        {
            animationGameObject.animation.Blend("jump", 0.0f, 0.3f);
            animationGameObject.animation.CrossFade("fall", 0.2f);

        }

		currentStatus = AnimationStatus.Jump;
			
        animationGameObject.animation.Blend("walk", 0.0f, 0.1f);
        animationGameObject.animation.Blend("run", 0.0f, 0.1f);

    }

}
コード例 #5
0
    void Update()
    {
        ThirdPersonController marioController = GetComponent <ThirdPersonController> ();
        float currentSpeed = marioController.GetSpeed();

        networkSyncAnimation = GetComponent <NetworkSyncAnimation> ();

        // Fade in run
        if (currentSpeed > marioController.walkSpeed)
        {
            animation.CrossFade("run");
            // We fade out jumpland quick otherwise we get sliding feet
            animation.Blend("jumpland", 0);
            networkSyncAnimation.SendMessage("SyncAnimation", "run");
            // Fade in walk
        }
        else if (currentSpeed > 0.1f)
        {
            animation.CrossFade("walk");
            // We fade out jumpland realy quick otherwise we get sliding feet
            animation.Blend("jumpland", 0);
            networkSyncAnimation.SendMessage("SyncAnimation", "walk");
            // Fade out walk and run
        }
        else
        {
            animation.CrossFade("idle");
            networkSyncAnimation.SendMessage("SyncAnimation", "idle");
        }

        animation["run"].normalizedSpeed  = runSpeedScale;
        animation["walk"].normalizedSpeed = walkSpeedScale;

        if (marioController.IsJumping())
        {
            if (marioController.IsCapeFlying())
            {
                animation.CrossFade("jetpackjump", 0.2f);
                networkSyncAnimation.SendMessage("SyncAnimation", "jetpackjump");
            }
            else if (marioController.HasJumpReachedApex())
            {
                animation.CrossFade("jumpfall", 0.2f);
                networkSyncAnimation.SendMessage("SyncAnimation", "jumpfall");
            }
            else
            {
                animation.CrossFade("jump", 0.2f);
                networkSyncAnimation.SendMessage("SyncAnimation", "jump");
            }
            // We fell down somewhere
        }
        else if (!marioController.IsGroundedWithTimeout())
        {
            animation.CrossFade("ledgefall", 0.2f);
            networkSyncAnimation.SendMessage("SyncAnimation", "ledgefall");
            // We are not falling down anymore
        }
        else
        {
            animation.Blend("ledgefall", 0.0f, 0.2f);
        }
    }