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 slidecoast · May 17, 2013 at 05:24 AM · movementcollidercharacterjumpglide

Making a character to glide

I am looking for a way to make my character to glide. So when a character jumps in the air, it will make him reach the ground at the lower speed. For example, some like this: http://www.youtube.com/watch?v=o5-V3zXAEsY

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by jayhatmaker · May 17, 2013 at 06:02 AM

I assume your talking about 2D game world? There are multiple ways to achieve this but here's one.

When glide is triggered, you can... reduce the downward vector by half.

*added you can possibly add a variable like

bool isGliding;

to your character. So user can hit certain key while jumping and etc. then you can reduce the downward vector.

Comment
Add comment · Show 6 · 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 slidecoast · May 17, 2013 at 06:50 AM 0
Share

Yes, the game is in 2d world. Where can I select glide? So I should use bool isGliding in my code?

avatar image jayhatmaker · May 17, 2013 at 08:16 AM 0
Share

Where can I select glide? So I should use bool isGliding in my code?

I believe there is no built in function to let your character glide. So you have to code the gliding behavior where your character movement is.

Is glide an option after jump only? or can a character glide by falling off from an edge?

If a character can only glide while jumping, your code should be in your jump code.

If your character can glide when s/he falls from a high place, and also in jump, you should create a function to check that your character is in air in other word, not on the ground.

It all depends on your code structure. It's a good practice to make a check list for an behavior like this.

  1. character is in air?

  2. Is a specific key hit? or glide automatically?

avatar image slidecoast · May 18, 2013 at 01:12 AM 0
Share

$$anonymous$$y plan is to have the character to glide when he jumps in the air. So the character can glide after they jump and fall from an edge.

At this point, I am confused a little. I have the character movement. So I am thinking would the code be something like this:

 transform.Translate (Vector3.down* speed * Time.deltaTime);

So if the character is falling, they can hold down a button which would make them glide or fall down at a lower speed.

avatar image jayhatmaker · May 18, 2013 at 01:38 AM 0
Share

if you are making a script like that, you can just half the speed while gliding. or, you can set a fixed value and make another "glideSpeed" variable.

avatar image slidecoast · May 18, 2013 at 01:54 AM 0
Share

Thanks. One more thing, in the code, how I can I detect when the character is falling or jumping? So if the character is falling or jumping, it can be detected so the glide function can be in full effect. Is there a way to detect it? if so, how can I write it in the code?

Show more comments
avatar image
0

Answer by ggpereira · Oct 08, 2020 at 01:21 AM

For all of you looking for a nice way, check the code below

 using UnityEngine;
 
 public class Glider : BaseBehaviour
 {
     /// <summary>
     /// The speed when falling
     /// </summary>
     [SerializeField]
     private float m_FallSpeed = 0f;
 
     /// <summary>
     /// 
     /// </summary>
     private Rigidbody2D m_Rigidbody2D = null;
 
     // Awake is called before Start function
     void Awake()
     {
         m_Rigidbody2D = GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update()
     {
         if (IsGliding && m_Rigidbody2D.velocity.y < 0f && Mathf.Abs(m_Rigidbody2D.velocity.y) > m_FallSpeed)
             m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, Mathf.Sign(m_Rigidbody2D.velocity.y) * m_FallSpeed);
     }
 
     public void StartGliding()
     {
         IsGliding = true;
     }
 
     public void StopGliding()
     {
         IsGliding = false;
     }
 
     /// <summary>
     /// Flag to check if gliding
     /// </summary>
     public bool IsGliding { get; set; } = false;
 
 }

Then trigger the StartGliding method when you hold the jump button or whatever

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

17 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

Related Questions

Making character to fly 1 Answer

controller.Move not working correctly 0 Answers

Character Controller sticky head.... Help!? 1 Answer

How to connect two spheres one to stay on top of another which is rotating moveing one (player body , head) 0 Answers

I Watched The Unity New Ball Rolling Game Tut, How I Can Make Jump,I Watched The New Unity Ball Rolling Tutorial, How I Can Make Jump? 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