• 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 umuthanozel · Sep 11, 2017 at 02:51 PM · physicsfirst-person-controller

My Character Jumps Higher Than It Should Be When Collides Into a Wall

As I said in the title, my problem is about the physics.

I'm trying to make a first person controller on my on. I can jump like one or two unit with my controller, but when I try to run into a wall or some object and hit jump, my character jumps like 0.2 units. But if I hit jump multiple times, my character can jump lots of higher, like 10 - 12 units. I tried to use a physics material to both my obstacles, floor and player with this settings:

alt text

After giving this, problem solved. But with this materials, if I try to climb a 30 degree ramp my character slides back and keeps sliding forever, even it is on straight floor. And another problem is jumping onto objects gives the same sliding-forever effect.

So, what should I do? I don't really wanted to use "Character Controller Component" because I wanted to make everything on my own. Must I use it?

Here is my code:

 using UnityEngine;
 
 public class Player : MonoBehaviour
 {
     [Header("Values")]
     public float speed;
     public float jumpThrust;
     public float cameraSensitivity;
     private Vector2 cameraAxis;
     private float horizontalAxis;
     private float verticalAxis;
     private Vector3 moveRotation;
     private float cameraY;
 
     [Space(20)]
     [Header("Statements")]
 
     public bool isGrounded;
     public bool canMove;
     public bool canLook;
     public bool isMenuActive;
     public bool isInventoryActive;
 
 
     [Space(20)]
     [Header("Assigments")]
     public PhysicMaterial[] physicMaterials;
     private Rigidbody rbody;
     private AudioSource aSource;
     private GameObject playerCamera;
     private Collider playerCollider;
     private GameObject playerInterface;
     private GameObject inventoryObject;
     private GameObject menuObject;
     private Animator menuAnimator;
     private Animator inventoryAnimator;
     
     
 
 
 
 
 
     void Awake ()
     {
         rbody = gameObject.GetComponent<Rigidbody>();
         aSource = gameObject.GetComponent<AudioSource>();
         playerCamera = gameObject.transform.Find("PlayerCamera").gameObject;
         playerCollider = gameObject.GetComponent<CapsuleCollider>();
         playerInterface = GameObject.FindGameObjectWithTag("PlayerInterface");
         inventoryObject = GameObject.Find("Inventory").gameObject;
         menuObject = GameObject.Find("Menu").gameObject;
         inventoryAnimator = inventoryObject.GetComponent<Animator>();
         menuAnimator = menuObject.GetComponent<Animator>();
 
 
     }
 
     private void Update()
     {
 
         
 
 
         if (Input.GetButtonDown("OpenInventory"))
         {
             if (isMenuActive)
             {
                 canLook = true;
                 canMove = true;
             }
             isMenuActive = false;
             menuAnimator.SetBool("isMenuActive", false);
             isInventoryActive = !isInventoryActive;
             inventoryAnimator.SetBool("isInventoryActive", isInventoryActive);
             canLook = !isInventoryActive;
             canMove = !isInventoryActive;
             Debug.Log("Current Inventory statement: " + isInventoryActive);
         }
 
         if (Input.GetButtonDown("OpenMenu"))
         {
             if (isInventoryActive)
             {
                 canLook = true;
                 canMove = true;
             }
             isInventoryActive = false;
             inventoryAnimator.SetBool("isInventoryActive", false);
             isMenuActive = !isMenuActive;
             menuAnimator.SetBool("isMenuActive", isMenuActive);
             canLook = !canLook;
             canMove = !canMove;
             Debug.Log("Current Menu statement: " + isMenuActive);
         }
 
 
         if (canLook)
         {
             CameraMovement();
         }
         
 
         if (canMove)
         {
             if (Input.GetButtonDown("Jump"))
             {
                 if (isGrounded)
                 {
                     Jump();
                 }
             }
         }
 
         if (isGrounded)
         {
             playerCollider.material = physicMaterials[1];
         }
         else
         {
             playerCollider.material = physicMaterials[0];
         }
 
         
 
 
     }
 
     void FixedUpdate ()
     {
 
         if (canMove)
         {
             Movement();
         }
         
         
 
     }
 
     void Movement()
     {
         horizontalAxis = Input.GetAxis("Horizontal");
         verticalAxis = Input.GetAxis("Vertical");
 
 
         moveRotation = new Vector3(horizontalAxis, 0, verticalAxis);
 
         moveRotation = transform.TransformDirection(moveRotation);
 
         moveRotation = Vector3.Normalize(moveRotation);
 
         rbody.MovePosition(transform.position + moveRotation * Time.deltaTime * speed);
 
     }
 
     void CameraMovement()
     {
         cameraAxis = new Vector2(Input.GetAxis("LookX"), Input.GetAxis("LookY"));
 
         cameraY -= cameraAxis.y * cameraSensitivity * Time.deltaTime;
 
         cameraY = Mathf.Clamp(cameraY, -75, 75);
 
         transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y + cameraAxis.x * Time.deltaTime * cameraSensitivity, transform.localEulerAngles.z);
 
         playerCamera.transform.localEulerAngles = new Vector3(cameraY, playerCamera.transform.localEulerAngles.y, playerCamera.transform.localEulerAngles.z);
     }
 
     void Jump()
     {
 
         RaycastHit ray;
         /*if(Physics.Raycast(transform.position, Vector3.down, out ray, 0.3f))
         {
             
         }
         */
 
         rbody.AddForce(transform.up * jumpThrust);
 
 
 
 
 
     }
 
     private void OnTriggerStay(Collider trigger)
     {
         isGrounded = true;
     }
     private void OnTriggerExit(Collider trigger)
     {
         isGrounded = false;
     }
 }
 


material.png (4.1 kB)
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 TheSOULDev · Sep 12, 2017 at 12:23 AM 0
Share

I'm no expert, but I'm pretty sure you want to add static and dynamic friction if you're using physics where static friction > dynamic friction.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

120 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

Related Questions

Enemies mess up force controlled Player 2 Answers

Problem with Colliders 1 Answer

First Person Prefab Stopping? 1 Answer

Physics based player controller problems 1 Answer

gravity doesnt seem to effect my first person controller....help! 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