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 JayFitz91 · Sep 02, 2014 at 02:14 PM · velocityplatformmomentumaddrelativetorque

Keep a rolling balls momentum

I am doing an infinite runner, the idea is to have a ball that is constantly rolling using AddRelativeTorque but I'm having a problem when it collides into the platforms. It kills the momentum and it needs to be built up again.

See the picture below, my ball has just hit the platform above it and now wont make it to the next platform, resulting in game over.

alt text

Is there a way I can hit the platform without losing the speed of the ball?

Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class platform : MonoBehaviour 
 {
     public Rigidbody target;
     public float speed = 5f;
     public int jumpHeight = 6;
     public bool isFalling = false;
     private bool isJumping = false;
 
     // Update is called once per frame
     void Update () 
     {
         if(Input.GetKeyDown(KeyCode.R))
         {
             Application.LoadLevel(0);
         }
         
         if(Input.GetButtonDown("Fire1") && isFalling == false)
             isJumping = true;
 
     }
     
     // Update is called once per frame
     void FixedUpdate () 
     {
         ballMovements ();   
     }
     
     void ballMovements()
     {
         rigidbody.AddRelativeTorque(Vector3.right * -1 * speed);
 
         //transform.Translate(1f * Time.deltaTime, 0f, 0f);
         
         if( isJumping )
         {
 
             isJumping = false;
             Debug.Log ("clicked");
             Vector3 temp = rigidbody.velocity;
             temp.y = jumpHeight;
             rigidbody.velocity = temp;
 
         }
         isFalling = true;
     }
     
     void OnCollisionStay()
     {
         isFalling = false;
     }
 }
capture.png (6.7 kB)
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

1 Reply

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

Answer by Owen-Reynolds · Sep 02, 2014 at 03:02 PM

You can play directly with the sideways motion, like your current code does for jumping. Suppose you want to have a minimum sideways speed of 1M/S:

 Vector3 v = rigidbody.velocity;
 if(v.x<1) v.x=1;
 rigidbody.velocity=v;

In theory, this would be in FixedUpdate, to be sure it resets speed before each move. But in Update would probably be fine.

Of course, you can have all sorts of fancy programming in the middle. Say you want it to bounce backwards, but then always climb some more. Remember it's furthest progress, when it hits something new, set a 1-second counter; and if it's past the time and in "old" territory, force (or smooth) the speed to 1.

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 JayFitz91 · Sep 02, 2014 at 03:55 PM 0
Share

Thanks ill mess around with this and see what I can come up with, thanks :)

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

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

Related Questions

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Player parent to platform problem 0 Answers

Climb Down Ladder in 2D Platformer Game 1 Answer

Is it possible to increase stopping distance with forcemode.velocitychange? 0 Answers

Continuing the momentum of the rigidbody 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