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 /
avatar image
0
Question by JamesInvi · Mar 29, 2018 at 07:58 PM · movementterrainplayercharacter controllerslope

Terrain Slope Bouncing

Hi, I have a very simple character controller movement script and it works fine except when i am supposed to run downhill. The player starts hopping down the slope and i would like it to walk normally. I have looked for a solution and found that it might be raycasting but i cant seem to make i work properly.... The most promising i found is this https://forum.unity.com/threads/player-character-movement-jumps-when-moving-down-the-slopes.497911/ but when i try to incorporate it in my script it doenst do what i want (so basically i don't understand what makes that solution work). Can anyone help?

Here is my script

 public class PlayerMovement : MonoBehaviour {
     public float Speed = 5.0f;
     public float JumpSpeed = 7.0f;
     public float TurnSpeed = 3.0f;
     public float gravity = 20.0f;
     private Vector3 moveDirection = Vector3.zero;
     private CharacterController controller;
 void Start () {
         controller = GetComponent<CharacterController>();
 }
 
 // Update is called once per frame
 void FixedUpdate () {
     transform.Rotate(0, Input.GetAxis("Horizontal") * TurnSpeed, 0);
     if (controller.isGrounded) {
         moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
         moveDirection = transform.TransformDirection(moveDirection);
         moveDirection *= Speed;
         if (Input.GetButton("Jump")) {
             moveDirection.y = JumpSpeed;
         }
     } else {
         moveDirection.y -= gravity * Time.deltaTime;
     }
     controller.Move(moveDirection * Time.deltaTime);
 }

}

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 neighborlee · Mar 27, 2019 at 01:17 PM

@JamesInvi

I"m far from an expert on this right now, but I wonder yes, it's prob some raycasting neeed as raycasting it used to keep a camera from going past the walls of caves or other objects, which is now a new unity script you can access in new component .

I can't imagine though its not a function of gravity, so maybe its a two part solution. I've delved deep into this myself, so far I've had no need, but now given after much terrain sculpting ( complex world), today I see I need SOME form of adjustment to avoid just what you're talking about- its annoying on some level.

BUT, so far anyway, my character isn't jumping, unless the angle of terrain is pretty darn steep, something in real life you'd also be forced into a 'jump', or rather literally a 'fall' position, tumble hard whatever ;0-

The idea is the raycast as somehow the computer needs you to tell it, HEY this is OK, use walk anim NOT jump, but also temporary , doesn't just setting a high value for slope variable work ?

Also this:

" Answer by robertbu · Aug 07, 2013 at 03:23 PM

Raycasting() is used to detect the slope. If you are going just for the slope of the terrain, then I suggest you use Colider.Raycast() rather than Physics.Raycast(). Sample code:

var hit : RaycastHit; var ray = new Ray(transform.position, Vector3.down); if (someCollider.Raycast(ray, hit)) { var slope = hit.normal; //Adjust character based on normal } This gives you back the normal to the slope:

alt text

Your question was unclear about how you wanted to adjust the rotation of your character. A lot of scripts I see here adjust the object to align with the normal. You can do that by:

transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation; "

from https://answers.unity.com/questions/509692/slope-detection.html

Hope this helps- I'm having the same problems ( you may already have fixed yrs given post almost a year old, let me know if you would).

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

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

139 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

Related Questions

How to Logically Match Ground Slope While Using This Code? 1 Answer

Using Navmesh for Player navigation 1 Answer

Slope Limit on Rigidbody First Person Controller 1 Answer

How to fix player jumping while watching downwards and moving with s key ? 1 Answer

game goes slow and characters fall of through the terrain 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