Exemplo n.º 1
0
    void FixedUpdate()
    {
        float rotationX = myTransform.localEulerAngles.y + Input.GetAxis("Mouse X") * xRotationSpeed * Time.deltaTime;

        myTransform.localEulerAngles = new Vector3(0, rotationX, 0);

        Vector3 Movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")).normalized;

        Movement  = transform.TransformDirection(Movement);
        Movement *= MoveSpeed;

        myRigidBody.AddForce(Movement);
        if (myRigidBody.velocity.magnitude > maxVelocity)
        {
            Vector3 vel = myRigidBody.velocity.normalized;
            vel *= maxVelocity;
            myRigidBody.velocity = vel;
        }

        if (playerState == FPSPlayerState.PLAYER_GROUNDED)
        {
            if (Input.GetButtonDown("Jump"))
            {
                playerState = FPSPlayerState.PLAYER_JUMPING;
                myRigidBody.AddForce(0, JumpHeight, 0);
            }
            if (Input.GetAxis("Vertical") == 0 && Input.GetAxis("Horizontal") == 0)
            {
                myRigidBody.velocity = Vector3.SmoothDamp(myRigidBody.velocity, Vector3.zero, ref dampVel, StopTime);
            }
        }
    }
Exemplo n.º 2
0
 public void OnCollisionEnter(Collision collision)
 {
     foreach (ContactPoint contact in collision.contacts)
     {
         if (Vector3.Dot(contact.normal, Vector3.up) > 0.5)
         {
             playerState = FPSPlayerState.PLAYER_GROUNDED;
         }
     }
 }
Exemplo n.º 3
0
 public override void HealthStateChanged(FPSPlayerState value)
 {
     gameObject.SetActive(value != FPSPlayerState.Dead);
 }
Exemplo n.º 4
0
 /// Subscribes to the property and is notified anytime the value changes.
 public override void HealthStateChanged(FPSPlayerState value)
 {
     base.HealthStateChanged(value);
 }
Exemplo n.º 5
0
 /// Subscribes to the property and is notified anytime the value changes.
 public virtual void HealthStateChanged(FPSPlayerState value)
 {
 }