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 /
This question was closed Oct 08, 2015 at 09:14 PM by Nirish-Alakhramsing for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Nirish-Alakhramsing · Oct 08, 2015 at 08:50 PM · physicscharactercontroller

3rd person character controller not responding correctly

Hello everyone,

I have been following a tutorial on you tube trying to learn more about 3rd person character controller. In did everything he did in the videos but yet, my character controller does not want to jump or it just slowly floats to the surface.

I thought i found the solution in the jump function, but it wasnt there. Im still a student in coding so thats why i cant figure out whats wrong here.

Anyone here who can help me out with this?

I have unity version 5.1.1f1

My setup is that i have the camera controller on the main camera, and the charactercontroller is on a cube.


 using UnityEngine;
 using System.Collections;
 
 public class CharacterController : MonoBehaviour {
 
     [System.Serializable]
     public class MoveSettings
     {
         public float forwardVel = 12;
         public float rotateVel = 100;
         public float jumpVel = 25f;
         public float distToGrounded = 0.01f;
         public LayerMask ground;
     }
 
     [System.Serializable]
     public class PhysSettings
     {
         public float downAccel = 0.75f;
     }
 
     [System.Serializable]
     public class InputSettings
     {
         public float inputDelay = 0.1f;
         public string FORWARD_AXIS = "Vertical";
         public string TURN_AXIS = "Horizontal";
         public string JUMP_AXIS = "Jump";
     }
 
     public MoveSettings moveSetting = new MoveSettings ();
     public PhysSettings physSetting = new PhysSettings ();
     public InputSettings inputSetting = new InputSettings ();
 
     Vector3 velocity = Vector3.zero;
     Quaternion targetRotation;
     Rigidbody rBody;
     float forwardInput, turnInput, jumpInput;
 
     public Quaternion TargetRotation{
         get { return targetRotation; }
     }
 
     bool Grounded()
     {
         return Physics.Raycast (transform.position, Vector3.down, moveSetting.distToGrounded, moveSetting.ground);
     }
 
     // Use this for initialization
     void Start () {
         targetRotation = transform.rotation;
         if (GetComponent<Rigidbody> ())
             rBody = GetComponent<Rigidbody> ();
         else
             Debug.LogError ("The character needs a rigidbody");
 
         forwardInput = turnInput = jumpInput = 0;
     }
 
     void GetInput(){
         forwardInput = Input.GetAxis (inputSetting.FORWARD_AXIS);
         turnInput = Input.GetAxis (inputSetting.TURN_AXIS);
         jumpInput = Input.GetAxisRaw (inputSetting.JUMP_AXIS);
     }
 
     // Update is called once per frame
     void Update () {
         GetInput ();
         Turn ();
     }
 
     void FixedUpdate(){
         Run ();
         JumP ();
 
         rBody.velocity = transform.TransformDirection (velocity);
     }
 
     void Run(){
         if (Mathf.Abs (forwardInput) > inputSetting.inputDelay) {
             //Move
             velocity.z = moveSetting.forwardVel * forwardInput;
         }
         else
             velocity.z = 0;
     }
 
     void Turn(){
         if (Mathf.Abs (turnInput) > inputSetting.inputDelay) {
             targetRotation *= Quaternion.AngleAxis (moveSetting.rotateVel * turnInput * Time.deltaTime, Vector3.up);
         }
             transform.rotation = targetRotation;
     }
 
     void JumP(){
         if (jumpInput > 0 && Grounded ()) {
             //jump
             velocity.y = moveSetting.jumpVel;
         } else if (jumpInput == 0 && Grounded ()) {
             //zero out our velocity.y
             velocity.y = 0;
         } else {
             //decrease velocity.y
             velocity.y -= physSetting.downAccel;
         }
     }
 }
 


And the camera controller is exactly the same as in the video, but il add the code here too, so you can copy, paste and test it for yourself with the same setup.

 using UnityEngine;
 using System.Collections;
 
 public class CameraController : MonoBehaviour {
 
 
     public Transform target;
     public float lookSmooth = 0.09f;
     public Vector3 offsetFromTarget = new Vector3(0, 6, -8);
     public float xTilt =10;
 
     Vector3 destination  = Vector3.zero;
     CharacterController charController;
     float rotateVel = 0;
 
 
     // Use this for initialization
     void Start () {
         SetCameraTarget (target);
     }
 
     void SetCameraTarget(Transform t)
     {
         target = t;
 
         if (target != null) 
         {
             if (target.GetComponent<CharacterController>())
             {
                 charController = target.GetComponent<CharacterController>();
             }
             else
             {
                 Debug.LogError("The camaera target needs a characterController");
             }
         } else
             Debug.LogError ("Your camera needs a target");
     }
 
 
     void LateUpdate(){
         //moving
         MoveToTarget ();
         //rotating
         LookAtTarget ();
     }
 
     void MoveToTarget(){
         destination = charController.TargetRotation * offsetFromTarget;
         destination += target.position;
         transform.position = destination;
     }
 
     void LookAtTarget(){
         float eulerYAngle = Mathf.SmoothDampAngle (transform.eulerAngles.y, target.eulerAngles.y, ref rotateVel, lookSmooth);
         transform.rotation = Quaternion.Euler (transform.eulerAngles.x, eulerYAngle, 0);
     }
     
 }
 


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

  • Sort: 
avatar image
0
Best Answer

Answer by Nirish-Alakhramsing · Oct 08, 2015 at 09:10 PM

After searching the web i found someone with almost the same problem. I am using a cube with a box collider. Now the distance to the ground was set to 0.1 and that caused it to hardly move forward or to jump.

So i played around somewhat and now i can walk and jump again. So im closing this subject.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to I make my player push off of the ground? 0 Answers

How to move while jumping? 1 Answer

How to make my Character run through walls with the use of the Character Controller component 1 Answer

CharacterController and Physics! 2 Answers

Skin Width doesn't fix wall sticking,Skin Width doesn't fix the character controller to stick to walls 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