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 Mischa · Dec 30, 2011 at 12:47 AM · charactercontrollergravitytransitionalgorithm

Transition Free Fall into Sinus Hovering

I have a character that should hover above a platform with a nice sinus based up and down movement.

Now the character jumps to this platform from above. I dont know from which height he jumps, so the his fall speed is variable. How would I compute that transition without my character touching the platform?

I'm thinking about this for a long time now, some help would make my day! :)

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Rod-Green · Dec 30, 2011 at 01:07 AM

You can't store the last hover height before the jump and include that into the jump arc calculation?

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 Mischa · Dec 30, 2011 at 10:13 AM 0
Share

Yes I can, but how would I calculate the jump arc? Its the mathematical part where I'm stuck.

avatar image
3

Answer by Rod-Green · Dec 30, 2011 at 07:29 PM

In that case here's a more complete answer:

 using System.Collections.Generic;
 using UnityEngine;
 
 public class Jumper : MonoBehaviour
 {
     public float m_upwardsMomentum = 200;
     public float m_forwardMomentum = 100;
     public Transform m_target;
     public bool m_doJump;
     public float m_gravity = 9.8f;
     public float m_terminalVelocityTime = 1.0f;
     public float m_minUpdate = 0.033333f;
     float m_lastUpdate;
     float m_fallSeconds;
     bool m_jumping;
     List<Vector3> m_trail;
     
     void UpdateJump()
     {
         float deltaTime = Time.time - m_lastUpdate;
         if(deltaTime <= m_minUpdate)
             return;
         
         
         
         m_lastUpdate = Time.time;
         if(m_trail == null)
             m_trail = new List<Vector3>();
         m_fallSeconds += deltaTime;
         
         Vector3 curPos = transform.position;
         Vector3 tarPos = m_target.position;
         float curHeight = curPos.y;
         
         
         float newHeight = curHeight;
         newHeight += m_upwardsMomentum * deltaTime;
         newHeight -= m_gravity * Mathf.Min(m_terminalVelocityTime, m_fallSeconds);
         
         if(newHeight <= tarPos.y - 0.01f)
         {
             m_jumping = false;
             newHeight = tarPos.y;
         }
         
         float newForward = curPos.x + (m_forwardMomentum * deltaTime);
         
         
         
         Vector3 newPos = curPos;
         newPos.y = newHeight;
         newPos.x = newForward;
         transform.position = newPos;
         
         m_trail.Add(newPos);
         
     }
     
     void Update()
     {
         if(m_doJump)
         {
             m_jumping = true;
             m_doJump = false;
             m_lastUpdate = Time.time - m_minUpdate;
         }
         
         if(m_jumping)
             UpdateJump();
         
         Color startTrail = Color.green;
         Color endTrail = Color.red;
         if(m_trail != null)
         {
             for (int i = 0; i < m_trail.Count - 1; i++)
             {
                 Color thisColor = Color.Lerp(startTrail, endTrail, (float)i/(float)m_trail.Count);
                 Debug.DrawLine(m_trail[i], m_trail[i + 1], thisColor);
                 
             }
         }
     }
     
         
 }
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 Mischa · Dec 30, 2011 at 09:00 PM

Thanks for the answer above. Its not exactely the solution to my problem, but helpful! Maybe an image can explain a bit better what I'm looking for: alt text The jump is no problem, the sinus floating is no problem, but how do I combine it? How do I do a transition from the jump to the sinus and vice versa?

Any ideas? Thanks for the answers so far!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

CharacterController isGrounded toggles value 2 Answers

3rd person Character Control with kinect 0 Answers

When my player climb something, after a certain point it start to float 0 Answers

Character Controler Localising movement and gravity 1 Answer

Fly Mode 2D + Rigid Body vs CharacterController problems 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