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
1
Question by Brogan89 · Oct 29, 2014 at 01:36 AM · charactercontrollersimplemove

how does SimpleMove apply gravity?

Calling all programer gurus!!

I am new to programming (started about 7 months) and I am starting to get the hang of it now. I am trying to build my own character controller so I can understand how to apply physics etc,

My question is how does .SimpleMove apply gravity?

     forward = transform.TransformDirection (Vector3.forward);
     curSpeed = speed * Input.GetAxis ("Vertical");
     controller.SimpleMove (forward * curSpeed);

this section of the cade is where the gravity is applied. But I don't understand how.

Can anyone explain this to me? The full code can be found here http://docs.unity3d.com/ScriptReference/CharacterController.SimpleMove.html

Thanks

Comment
Add comment · Show 3
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 robertbu · Oct 29, 2014 at 01:55 AM 0
Share

As a guess, they are using something similar to what is done in the sample script for CharacterController.$$anonymous$$ove(). You might put two character side by side using $$anonymous$$ove() and Simple$$anonymous$$ove() and compare the jump behavior.

avatar image Brogan89 · Oct 29, 2014 at 01:57 AM 0
Share

Yea, I'm starting to think it's something "under the hood" kind of thing. Similar to the way it doesn't need Time.deltaTime .. if that makes sense

avatar image Brogan89 · Oct 29, 2014 at 02:59 AM 0
Share

the main reason why I wanted to know because I like the Simple$$anonymous$$ove() feel, but I couldn't add jump very easily.. $$anonymous$$ove() is easier to add jump but I didn't want strafing. I also wanted to add different animations for backward and forward motion and apply sprint... this is what I got, and works fine!

There is probably better ways to optimise this script but I feel like a big boy programmer now :)

public float speed = 10.0F; public float sprintSpeed = 20.0f; public float rotateSpeed = 3.0f; public float jumpHeight = 8.0F; public float gravity = 20.0F;

 Vector3 moveDirection = Vector3.zero;

 CharacterController controller;

 bool sprint = false;
 

 void Update() 
 {
     CharacterController controller = GetComponent<CharacterController>();
     if (controller.isGrounded) 
     {
         // for movement forward
         moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));

         // for adding animations to movement direction
         if (moveDirection.z > 0)
             Debug.Log ("moving forward");
         else if (moveDirection.z < 0)
             Debug.Log ("moving backward");
         else
             Debug.Log ("idle");


         // spins ins$$anonymous$$d of straif
         transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0); 

         moveDirection = transform.TransformDirection(moveDirection);

         // toggles between speed and sprintSpeed
         if(sprint == true)
             moveDirection *= sprintSpeed;
         else
             moveDirection *= speed;


         // apply sprint which is set up to "left shift"
         if (Input.GetButton ("Run"))
             sprint = true;
         else 
             sprint = false;

         // apply jump
         if (Input.GetButton("Jump"))
             moveDirection.y = jumpHeight;
     }
     // apply gravity
     moveDirection.y -= gravity * Time.deltaTime;
     // apply movement
     controller.$$anonymous$$ove(moveDirection * Time.deltaTime);
 }

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Brogan89 · May 14, 2019 at 08:20 PM

The answer to the question can be found here

"SimpleMove takes the speed as parameter and will move the character accordingly. On top of that, the character will respond to gravity. That’s the only physic you’ll get with the Character Controller. The downside is that the Y axis velocity is ignored by this method"

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
avatar image
-1

Answer by gribbly · Oct 29, 2014 at 01:40 AM

SimpleMove is not applying gravity. The physics system is applying gravity via the rigidbody component attached to the gameobject.

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 Brogan89 · Oct 29, 2014 at 01:47 AM 0
Share

But I am not using a rigidbody. I am using a characterController. Plus, in the API of Simple$$anonymous$$ove it says "Gravity is automatically applied"

avatar image gribbly · Oct 29, 2014 at 08:53 PM 0
Share

You're right, my bad.

avatar image
0

Answer by stjernerlever · May 14, 2019 at 01:37 PM

Did you ever find out? :)

I am currently trying to make gravity apply to my NPCs. They wander about with a script that uses SimpleMove, and they will fall towards the ground, just very slowly. This means they can walk down a hill, but if they attempt to run down the hill, they will run off the terrain and glide through the air.

Comment
Add comment · Show 1 · 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 Brogan89 · May 14, 2019 at 08:18 PM 0
Share

oh man this was a long time ago lol. Yea, pretty much the only physics parameter applied with CharacterController.Simple$$anonymous$$ove() is gravity.

I would suggest using a Rigidbody though. It will be easier to set up, CharacterController you have to do a lot of the code yourself. Which can be an up side because you'll have more control.

Checkout this link https://medium.com/ironequal/unity-character-controller-vs-rigidbody-a1e243591483

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

Any way to disable SimpleMove's sliding? 1 Answer

Charactercontroller.move affecting rotation 1 Answer

Problem with CharacterController.SimpleMove 0 Answers

Move() function doesn't work on character controller! 0 Answers

SimpleMove with Chasing 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