Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 H3avyRex · Feb 22, 2016 at 09:52 PM · unity 52d game

Alternating buttons to keep moving.

Hello there,

I am currently developping a little prototype in C# on Unity 5.3. The game is a 2D Side scroll game where the player mainly has to walk (same movement system as Darkest Dungeon / link : https://youtu.be/J-X5-KRJ2JQ?t=997 )

The kind of input I want for the player to move is a direction and a way to accelerate. I provide my diretion using a joystick, and I want the player to accelerate by pressing alternately RT and LT on a xbox 360 controller.

I want also my max speed to fit the rhythm the player is pressing those 2 inputs.

Do you know a way to do it ? Even with only one button, no alternation aspect, it will be a beginning.

Thank you for your time !

Comment
Add comment · Show 1
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 rajavamsidhar_gvs · Feb 23, 2016 at 12:21 PM 0
Share

hi..there is a manual in unity wiki. here you go link

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dragday · Feb 23, 2016 at 01:12 PM

try to use

Input.GetButton()

and change the movespeed of the player.

I think that would do it.

You can set a time inside, so the "shorter"is the times when pressed the other button the faster it is.

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 jayjf · Feb 23, 2016 at 01:03 PM

Replace the GetKeyDown methods with the methods for the buttons. Otherwise this should do the trick. This might need some fine tuning. For example, if you set optimal time to a high value you might want to set the speed to a minimum value.

    public class AlternatingButtons : MonoBehaviour {

     private float _lastInputTime;
     private float _maxSpeed = 10;
     private float _optimalTime = 0.5f; //your optimal time between inputs in sec
     private float _speed;

     private bool _lastInputRight = false;

     void Update()
     {
         if(Input.GetKeyDown(KeyCode.A))
         {
             if(_lastInputRight)
             {
                 CalcSpeed();
             }
             _lastInputRight = false;
         }
         if (Input.GetKeyDown(KeyCode.D))
         {
             if(!_lastInputRight)
             {
                 CalcSpeed();
             }
             _lastInputRight = true;
         }
     }

     private void CalcSpeed()
     {
         var timeSinceLastInput = Time.time - _lastInputTime;
         var speedParam = 1 - Mathf.Clamp01(Mathf.Abs(_optimalTime - timeSinceLastInput));
         _speed = Mathf.Lerp(0, _maxSpeed, speedParam);
         _lastInputTime = Time.time;
         Debug.Log(_speed);
     }
 }
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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Firing with the mouse 2D. 3 Answers

Unity 5.4.0f3 Personal - UI not updating after Build. 1 Answer

2D player keeps getting dragged to the left for some reason. 0 Answers

Scrolling Jitters in Unity 5.2.3 0 Answers

Sprites not recognized as whole-spinning in different directions 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