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 WitchTheWicked2 · Jan 15, 2012 at 08:31 AM · charactercontrollerslopeslopes

CharacterController Slope Problems

Hello, I have a game where my character is moving forwards and when it reaches a slope incline of 15 degrees it slows down because i set the characters motion by setting targetDirection.z =1.0;

But, on slopes the character has trouble, I want to maintain its speed while going up an incline i tried messing with targetDirection.y = 16.0f but when i did that it, the character started to bounce up and down and I couldn't control the jump, so i lowered it to like 1.0f, and i didn't notice anything and the jump was wierd because it keeps me in the air above the ground floating.

I wanted to like rotate the characters axis origin to match the slope of the plane its on, but i dont know how to do that here is my character controller code (its modified)

 function UpdateSmoothedMovementDirection ()

{ var lockCameraTimerSaved; var controller : CharacterController = GetComponent(CharacterController); var cameraTransform = Camera.main.transform;

 var grounded = IsGrounded();
 
 // Forward vector relative to the camera along the x-z plane    
 var forward = cameraTransform.TransformDirection(Vector3.forward);
 forward.y = 0;
 forward = forward.normalized;

 // Right vector relative to the camera
 // Always orthogonal to the forward vector
 var right = Vector3(forward.z, 0, -forward.x);

 var v = 1;
     if (b_onAndroid)
 {
     h = -Input.acceleration.y*.5;
 }
 else
 {
     //For Desktop uncomment this otherwise PlayMaker FSM sets it.
     h = Input.GetAxisRaw("Horizontal");
 }

 
 var wasMoving = isMoving;
 isMoving = Mathf.Abs (h) > 0.1 || Mathf.Abs (v) > 0.1;
 
 
 // Target direction relative to the camera
 targetDirection = Vector3.zero;

 
 //move character forward
 targetDirection.z = 1.0;
 
 
 // Grounded controls
 
     // We store speed and direction seperately,
     // so that when the character stands still we still have a valid forward direction
     // moveDirection is always normalized, and we only update it if there is user input.
     if (targetDirection != Vector3.zero)
     {
             moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
             moveDirection = moveDirection.normalized;
     }
     
     // Smooth the speed based on the current target direction
     var curSmooth = speedSmoothing * Time.deltaTime;
     
     // Choose target speed
     //* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways
     var targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0);
 
     _characterState = CharacterState.Idle;
     
     targetSpeed *= runSpeed;
     _characterState = CharacterState.Running;
     
     moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
 

     

}

Also, running downhill its messed up as well

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I make my character fall off slopes grater than its slope limit? 0 Answers

Sliding down a slope with a character controller 1 Answer

A node in a childnode? 1 Answer

2D Game RigidBody Vs. Character Controller 2 Answers

How to rotate a character controller by exactly 90 degrees with one key 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