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 DealWithMeal · Sep 17, 2014 at 04:48 PM · charactercontrollergravitycharacter controllerfallingcharactermotor

CharacterController how to disable acceleration of falling when moving in the air?

I have a scene, there is a cube with attached CharacterConrtoller and my script which you can see below.

Cube falls as wanted, but if I press any of WASD or arrows, it starts to fall much more faster. How to deal with it?

Watch screenshot of my scene. No scripts attached to Camera or Plain (click on 1.png in the bottom for full size)

Screenshot of my scene. No scripts attached to Camera or Plain

Screenshots of Y-change without anything pressed and with W pressed:

http://i008.radikal.ru/1409/28/4c55ae5789af.png

http://i023.radikal.ru/1409/1e/0882ae1c41d4.png

using UnityEngine; using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

 public float speed = 6.0F;
 public float gravity = 0.0F;
 private Vector3 moveDirection = Vector3.zero;
 // Update is called once per frame
 void Update () {

     CharacterController controller = GetComponent<CharacterController>();

     moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
     moveDirection = transform.TransformDirection(moveDirection);
     moveDirection *= speed;            

     moveDirection.y -= gravity * Time.deltaTime;
     controller.Move(moveDirection * Time.deltaTime);
 
 }

}

1.png (375.3 kB)
Comment
Add comment · Show 7
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 Bluntweapon · Sep 17, 2014 at 06:58 PM 0
Share

Nothing in this code suggests why it would. In fact, it's copied straight from the scripting reference. Something else must be changing your Gravity values at runtime.

avatar image DealWithMeal · Sep 17, 2014 at 09:47 PM 0
Share

I will add a screenshot now...

avatar image Bluntweapon · Sep 18, 2014 at 03:58 AM 0
Share

This is ridiculous. Your code applies gravity linearly...because every frame you reset moveDirection.y to 0, then apply gravity to it.

I'm going to ask for a favour, @DealWith$$anonymous$$eal. Put in Debug.Log( moveDirection.y ) after controller.$$anonymous$$ove and take a screenshot of the results when you don't press any buttons, and when you do press buttons.

avatar image DealWithMeal · Sep 18, 2014 at 08:47 AM 0
Share

@Bluntweapon added two screenshots... it is super weird, lol

avatar image Bluntweapon · Sep 18, 2014 at 02:50 PM 0
Share

Hmm, both screenshot points to about -0.8 for moveDirection.y, so it's not your code that's doing it; if fact, you've proved my point, and are only applying gravity linearly, so your cube should be moving downwards at a linear rate.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by StianC · Sep 17, 2014 at 08:08 PM

Try moving anything physics related to a FixedUpdate() function.

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 DealWithMeal · Sep 17, 2014 at 09:53 PM 0
Share

But $$anonymous$$ove() function must not use physics, but it seems that it uses.

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

Hilarious Gravity defect i don't know how to fix 1 Answer

Use Mouse as Direction for Character Movement? 0 Answers

character gravity problem 1 Answer

Change gravity point on trigger 0 Answers

Character Controller / Charactor Motor has no inputs? 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