Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Noxcy · Dec 23, 2019 at 01:32 AM · movementblendermovement script

Imported 3D Model doesn't react to Rigidbody Movement Script

I'm lost as to what's happening because this same script works on a 3D capsule, but won't with my imported .fbx model. Also I can't use a character controller because then I can't get physics on my character. I'd appreciate any ideas on how I could fix this problem. If I need to add anything else to make my problem more clear I'd be happy to.

 using System.Collections.Generic;
 using UnityEngine;
 
 
 public class RigidbodyCharacter : MonoBehaviour
 {
     Rigidbody rb;
   
 
     public Transform LookTransform;
     public Vector3 Gravity = Vector3.down * 9.81f;
     public float RotationRate = 0.1f;
     public float Velocity = 8;
     public float GroundControl = 1.0f;
     public float AirControl = 0.2f;
     public float JumpVelocity = 5;
     public float GroundHeight = 1.1f;
     private bool jump;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         rb.freezeRotation = true;
         rb.useGravity = false;
     }
 
     void Update()
     {
         jump = jump || Input.GetButtonDown("Jump");
     }
 
     void FixedUpdate()
     {
 
 
         // Cast a ray towards the ground to see if the Walker is grounded
         bool grounded = Physics.Raycast(transform.position, Gravity.normalized, GroundHeight);
 
         // Rotate the body to stay upright
         Vector3 gravityForward = Vector3.Cross(Gravity, transform.right);
         Quaternion targetRotation = Quaternion.LookRotation(gravityForward, -Gravity);
         rb.rotation = Quaternion.Lerp(rb.rotation, targetRotation, RotationRate);
 
         // Add velocity change for movement on the local horizontal plane
         Vector3 forward = Vector3.Cross(transform.up, -LookTransform.right).normalized;
         Vector3 right = Vector3.Cross(transform.up, LookTransform.forward).normalized;
         Vector3 targetVelocity = (forward * Input.GetAxis("Vertical") + right * Input.GetAxis("Horizontal")) * Velocity;
         Vector3 localVelocity = transform.InverseTransformDirection(rb.velocity);
         Vector3 velocityChange = transform.InverseTransformDirection(targetVelocity) - localVelocity;
 
         // The velocity change is clamped to the control velocity
         // The vertical component is either removed or set to result in the absolute jump velocity
         velocityChange = Vector3.ClampMagnitude(velocityChange, grounded ? GroundControl : AirControl);
         velocityChange.y = jump && grounded ? -localVelocity.y + JumpVelocity : 0;
         velocityChange = transform.TransformDirection(velocityChange);
         rb.AddForce(velocityChange, ForceMode.VelocityChange);
 
         // Add gravity
         rb.AddForce(Gravity * rb.mass);
 
         jump = false;
     }
 
 }


Comment
Add comment · Show 1
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
avatar image Pinkuboxu · Dec 23, 2019 at 07:44 PM 0
Share

What comes to $$anonymous$$d off the top of my head, since your script doesn't have the command above the class definition to automatically acquire the rigid-body, is to make sure your object also has the rigidbody component on it or that the script is finding it properly. $$anonymous$$aking it "public Rigidbody rb;" will help you see in the scripts inspector if it's attaching properly. If you put "[RequireComponent(typeof(Rigidbody))]" above the beginning of the class it will automatically insure you have one on the object.

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

264 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 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

One of meshes keeps following the camera in scene mode for some reason? 1 Answer

Face direction of a Vector 3 1 Answer

How do I make my player jump? 1 Answer

How to make an object go the direction it is facing? (Im new) 0 Answers

How to get root motion from animations made in blender? 1 Answer


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