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 ULTIMATE306 · Jul 04, 2020 at 02:00 PM · troubleshooting

My character cant jump

this is my player Controller script

 using UnityEngine;
 
 [RequireComponent(typeof(Animator))]
 [RequireComponent(typeof(ConfigurableJoint))]
 [RequireComponent(typeof(PlayerMotor))]
 public class PlayerController : MonoBehaviour
 {
 
     [SerializeField]
     private float speed = 5f;
     [SerializeField]
     private float lookSensitivity = 3f;
 
     [SerializeField]
     private float thrusterForce = 1000f;
 
     [Header("Spring settings:")]
     [SerializeField]
     private JointDriveMode jointMode = JointDriveMode.Position;
     [SerializeField]
     private float jointSpring = 20f;
     [SerializeField]
     private float jointMaxForce = 40f;
 
     // Component caching
     private PlayerMotor motor;
     private ConfigurableJoint joint;
     private Animator animator;
 
     void Start()
     {
         motor = GetComponent<PlayerMotor>();
         joint = GetComponent<ConfigurableJoint>();
         animator = GetComponent<Animator>();
 
         SetJointSettings(jointSpring);
     }
 
     void Update()
     {
         //Calculate movement velocity as a 3D vector
         float _xMov = Input.GetAxis("Horizontal");
         float _zMov = Input.GetAxis("Vertical");
 
         Vector3 _movHorizontal = transform.right * _xMov;
         Vector3 _movVertical = transform.forward * _zMov;
 
         // Finale movement vector
         Vector3 _Velocity = (_movHorizontal + _movVertical) * speed;
 
         // Animate movement
         animator.SetFloat("ForwardVelocity", _zMov);
 
         //Apply movement
         motor.Move(_Velocity);
 
         //Calculate rotation as a 3D vector (turning around)
         float _yRot = Input.GetAxisRaw("Mouse X");
 
         Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity;
 
         //Apply rotation
         motor.Rotate(_rotation);
 
         //Calculate camera rotation as a 3D vector (turning around)
         float _xRot = Input.GetAxisRaw("Mouse Y");
 
         float _cameraRotationX = _xRot * lookSensitivity;
 
         //Apply camera rotation
         motor.RotateCamera(_cameraRotationX);
 
         // Calculate the thrusterforce based on player input
         Vector3 _thrusterForce = Vector3.zero;
         
         if (Input.GetButton("Jump"))
         {
             _thrusterForce = Vector3.up * thrusterForce;
             SetJointSettings(0f);
         } else
         {
             SetJointSettings(jointSpring);
         }
 
     }
 
     private void SetJointSettings (float _jointSpring)
     {
         joint.yDrive = new JointDrive {
             mode = jointMode,
             positionSpring = _jointSpring, 
             maximumForce = jointMaxForce
         };
     }
 
 }


And this is my Player Motor Script,

 using UnityEngine;
 
 [RequireComponent(typeof(Rigidbody))]
 public class PlayerMotor : MonoBehaviour
 {
 
     [SerializeField]
     private Camera cam;
 
     private Vector3 velocity = Vector3.zero;
     private Vector3 rotation = Vector3.zero;
     private float cameraRotationX = 0f;
     private float currentCameraRotationX = 0f;
     private Vector3 thrusterForce = Vector3.zero;
 
     [SerializeField]
     private float cameraRotationLimit = 85f;
 
     private Rigidbody rb;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     //Gets a movement vector
     public void Move(Vector3 _velocity)
     {
         velocity = _velocity;
     }
 
     //Gets a rotational vector
     public void Rotate(Vector3 _rotation)
     {
         rotation = _rotation;
     }
 
     //Gets a rotational vector for the camera
     public void RotateCamera(float _cameraRotationX)
     {
         cameraRotationX = _cameraRotationX;
     }
 
     //Get a force Vector for our thrusters
     public void ApplyThruster(Vector3 _thrusterForce)
     {
         thrusterForce = _thrusterForce;
     }
 
     // Run every physics iteration
     void FixedUpdate()
     {
         PerformMovement();
         PerformRotation();
     }
 
     //Perform movement based on velocity variable
     void PerformMovement()
     {
         if(velocity != Vector3.zero)
         {
             rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
         }
 
         if (thrusterForce != Vector3.zero)
         {
             rb.AddForce(thrusterForce * Time.fixedDeltaTime, ForceMode.Acceleration);
         }
 
     }
 
     //Perform rotation
     void PerformRotation()
     {
         rb.MoveRotation(rb.rotation * Quaternion.Euler (rotation));
         if(cam != null)
         {
             // Set our rotation and clamp it
             currentCameraRotationX -= cameraRotationX;
             currentCameraRotationX = Mathf.Clamp(currentCameraRotationX, -cameraRotationLimit, cameraRotationLimit);
 
             //Apply our rotation to the transform of our camera
             cam.transform.localEulerAngles = new Vector3(currentCameraRotationX, 0f, 0f);
         }
     }
 
 }
 




i am using a brackeys tutorial.

script-error-pic.png (168.0 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mbro514 · Jul 04, 2020 at 05:33 PM

In your PlayerController Script, you're setting _thrusterForce to thrusterForce * Vector3.up, but afterwards, you don't move your player by _thrusterForce. If you add in

 motor.ApplyThruster(_thrusterForce);

your script should work fine.

Comment
Add comment · Show 2 · Share
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 ULTIMATE306 · Jul 05, 2020 at 04:42 AM 0
Share

Thanks a lot, its working now. :) @mbro514 .

avatar image mbro514 ULTIMATE306 · Jul 05, 2020 at 03:30 PM 0
Share

You're welcome! I'm glad that I could help.

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

130 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

Related Questions

Shadows showing up through geo in forward rendering with directional light 0 Answers

Troubles with directional light on Android 0 Answers

Alternate Ways of Controlling a Character's Rotation with a Mouse (FPS) 0 Answers

Issue with torch script in C# 1 Answer

Player Game Object moves by itself 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