Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by emoney101skeleton · Aug 03, 2020 at 11:21 AM · rigidbodyanimatorscript.controller

Is This Animator/Movement Script Right?

So I'm Setting up My Animator Script and I Don't Know I Couldn't Find Much Animator Scripts That Could Help me ad To My Movement Script So Here It Is

 using UnityEngine;
 
 public class FPSFirstPerson : MonoBehaviour
 {
 
 public Transform camera;
 public Rigidbody rb;
 public Animator animator;
 
 public float camRotationSpeed = 5f; 
 public float cameraMinimumY = -60f;
 public float cameraMaximumY = 75f;
 public float rotationSmoothSpeed = 10f;
 
 public float walkSpeed = 9f;
 public float runSpeed = 14f;
 public float maxSpeed = 20f; 
 public float jumpPower = 30f;
 
 public float _extraGravity = 45;
 
 float bodyRotationX; 
 float camRotationY;
 Vector3 directionIntentX;
 Vector3 directionIntentY;
 float speed;
 
 public bool grounded;
 
 public void Awake()
 {
     animator = GetComponent<Animator>();
 }
 
 
 void Update()
 {
     LookRotation();
     Movement();
     extraGravity();
     GroundCheck();
     if(grounded && Input.GetButtonDown("Jump"))
     {
         Jump();
     }
 
 }
 
 void LookRotation()
 {
     Cursor.visible = false;
     Cursor.lockState = CursorLockMode.Locked;
 
     bodyRotationX += Input.GetAxis("Mouse X") * camRotationSpeed;
     camRotationY += Input.GetAxis("Mouse Y") * camRotationSpeed;
 
     camRotationY = Mathf.Clamp(camRotationY, cameraMinimumY, cameraMaximumY);
 
 
     Quaternion camTargetRotation = Quaternion.Euler(-camRotationY, 0, 0);
     Quaternion bodyTargetRotation = Quaternion.Euler(0, bodyRotationX, 0);
 
 
     transform.rotation = Quaternion.Lerp(transform.rotation, bodyTargetRotation, Time.deltaTime * rotationSmoothSpeed);
 
     camera.localRotation = Quaternion.Lerp(camera.localRotation, camTargetRotation, Time.deltaTime * rotationSmoothSpeed);
 }
 
 void Movement() 
 {
 
     directionIntentX = camera.right;
     directionIntentX.y = 0;
     directionIntentX.Normalize();
 
     directionIntentY = camera.forward;
     directionIntentY.y = 0;
     directionIntentY.Normalize();
 
     rb.velocity = directionIntentY * Input.GetAxis("Vertical") * speed + directionIntentX * Input.GetAxis("Horizontal") * speed + Vector3.up * rb.velocity.y;
     rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
 
     if (directionIntentX != 0) animator.SetFloat("Fight Idle", true);
     else animator.SetFloat("Walkingn", false);
     
     if (directionIntentY != 0) animator.SetFloat("Fight Idle", true);
     else animator.SetFloat("Walking", false);
     
     if (directionIntentX != 1) animator.SetFloat("Walking", true);
     else animator.SetFloat("Walking", false);
     
     if (directionIntentY != 1) animator.SetFloat("Walking", true);
     else animator.SetFloat("Walking", false);
 
     if (directionIntentX != 2) animator.SetFloat("Run", true);
     else animator.SetFloat("Run", false);
 
     if (directionIntentY != 2) animator.SetFloat("Run", true);
     else animator.SetFloat("Run", false);
 
     if(Input.GetKey(KeyCode.LeftShift))
     {
         speed = runSpeed;
     }
     if(!Input.GetKey(KeyCode.LeftShift))
     {
         speed = walkSpeed;
     }
 
 
 }
 
 void extraGravity()
 {
     rb.AddForce(Vector3.down * _extraGravity );
 }
 
 void GroundCheck()
 {
     RaycastHit groundHit;
     grounded = Physics.Raycast(transform.position, -transform.up, out  groundHit, 1.25f);
 }
 
 void Jump()
 {
     rb.AddForce(Vector3.up * jumpPower, ForceMode.Impulse);
 }
 }

So I Just Wanted To Have Anyone Correct It If, I got Anything Wrong Or Something to Change Any Help Given Thank You

scripting rigidbody

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

237 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use Animator Override Controler in script? 0 Answers

Can i make more gripped rigidbody sphere Controllers 0 Answers

What's the difference between animation and animator ? 0 Answers

Animations with no Y position changes gets affected by Rigidbody Gravity 0 Answers

Creation of a truck game 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges