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 Persona · Nov 15, 2010 at 04:40 PM · gravityspeedjumpingfalling

Slowing down a fall from a Jump

Does anyone know how to slow down a character when falling down? Here's the movement code I'm using:

private var jumpSpeed : float = 12.0; private var gravity = 100.0; private var moveDirection : Vector3 = Vector3.zero; private var charController : CharacterController; function Update () { if(charController.isGrounded == true) {

     if(Input.GetButtonDown("Jump")){
     moveDirection.y = jumpSpeed;
     //audio.PlayOneShot(Jump);
 }

 }

 moveDirection.y -= gravity * Time.deltaTime;
 charController.Move(moveDirection * (Time.deltaTime * walkSpeed));
 transform.position.z = 0.0;

}

What I mean is that the player jumps and lands too fast for the player to make accurate movements while trying to jump on a platform.

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

4 Replies

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

Answer by Persona · Dec 14, 2010 at 11:04 PM

Never mind. I got it now by playing with the variables.

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 Proclyon · Nov 16, 2010 at 12:32 PM

You should split your editing into parts

if horizontal move --> moveDirection = new Vector3(moveDirection.x + changeValue in x, moveDirection.y, moveDirection.z);

if B vertical move --> change moveDirection vector = new Vector3(moveDirection.x, moveDirection.y + changeValue in y*/, moveDirection.z);

if C --> change moveDirection vector = new Vector3(moveDirection.x, moveDirection.y, moveDirection.z + changeValue in z);

Splitting the logic like this can help you keep track of who is doing what when (The flow of the code)

The problem is that only JS will let you change the existing x .y .z. It's not the perfect solution since u keep reconstructing and editing exsiting values. But it demonstrates that you can maintain good logic in the code.

To fall down slower now looks like a simple solution.

Change the y value in the B example on the event when u want it and keep doing that with a small number untill you want to stop. The stop condition can be a clock , a max speed value or user input. Whatever you like

EDIT 11/22/2010 22:45:

Make a variable , sample name V

//Initial value is (0.0f, 0.0f, 0.0f) private Vector3 V = new Vector3.zero; private float jumpHeight = 10.0f;

//Null object private CharacterController c;

//Now to get the motion you want into the V vector with destroying previous changes V = new Vector3(V.x, V.x + jumpHeight, V.z);

//Get the character controller on this object if(GetComponent<CharacterController>() != null) { //Set the (not null by proof) component into the variable c = GetComponent<CharacterController>(); }

 //Execute the move with the following unity function
 //It demands a parameter so it knows WHERE to go
 c.Move(V);

Sorry about all the C#. I don't really know where to start in JS except just putting var everywhere. Hope this helps out enough

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 Persona · Nov 22, 2010 at 09:23 PM 0
Share

Yeah, I can't see where you're going at here. No, I can see but I can't see how to code that.

avatar image Proclyon · Nov 22, 2010 at 09:45 PM 0
Share

Editing for a sample to help explain

avatar image
0

Answer by StephanK · Nov 15, 2010 at 04:53 PM

What do you mean by slowing down? He will fall slower and slower and finally stop falling down? You have an error in your script, you are applying walkspeed to your gravity, which you probably don't want to.

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
0

Answer by Thelo · Nov 16, 2010 at 10:38 AM

Most platform games have a maximum speed at which you fall down (or jump up), I'll assume that this is what you mean. In that case, just limit the maximum vertical speed difference you apply to the character:

var V_SPEED_LIMIT : float = 5.0;

var limitedVerticalSpeed : Vector3 = Vector3( moveDirection.x, Mathf.Clamp(moveDirection.y, -V_SPEED_LIMIT, V_SPEED_LIMIT), moveDirection.z);

charController.Move(limitedVerticalSpeed * Time.deltaTime);

As spree pointed out, you probably don't want to apply your walkSpeed to gravity.

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 Persona · Nov 22, 2010 at 09:22 PM 0
Share

But that applies to the general movement, not the falling part. If I alter that then the entire movement system is affected.

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

No one has followed this question yet.

Related Questions

Problem of gravity 1 Answer

unity 5 game 2.5 trouble jumping 2 Answers

Constant speed when free-falling... Why?? 1 Answer

Rigidbody y velocity is stuck on 0, gravity is not turned off. 2 Answers

How would I limit jumps to 1 until the player touches the ground again?,What do I need to add to limit the jumps to 1 until the player hits the ground again? 0 Answers


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