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 FritzPeace · Feb 12, 2015 at 08:29 PM · c#2dfps

Augmenting a speed linked to a Vector 2

Hey Guys, I am making a game, and need some help. I have this player that will under some circunstances go down. When it goes down I want it to act like flappy birds, by having its speed augmenting every frame.

     //Set the gravity
     public Vector2 gravity = new Vector2 (0, -10);

     //Makes the player fall while the space bar is not pressed
     //How can I make it every frame go down faster?
     if (Jumping == false) 
     {
         rigidbody2D.velocity = Vector2.zero;
         rigidbody2D.AddForce(gravity);
         if (Input.GetKeyDown(KeyCode.Space)){
             Jumping = true;
         }
     }



I am new to C# and Unity, so I really need some help and maybe an explication.

And how can I know my game FPS? How can I change it? Thanks.

Comment
Add comment · Show 2
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 Glurth · Feb 16, 2015 at 06:19 PM 0
Share

this is a duplicate of a question you already asked. http://answers.unity3d.com/questions/898277/some-help-with-a-movement-code.html

You never replied to my last comment on that one(about the variable initialization), and then opened an identical question. Not cool Fritz.

avatar image FritzPeace · Feb 16, 2015 at 06:39 PM 0
Share

Sorry Glurth. I read your answer there, but here I am making another question. There I was trying to make it work, here I asked something slightly different.

Sorry once again bud.

1 Reply

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

Answer by InvincibleCat · Feb 12, 2015 at 08:52 PM

 public float VerticalAcceleration = -2.0f;
 public float VerticalSpeedMax = 10.0f;

 private Vector2 _currentSpeed = Vector2.zero;

and then, instead of your rigidbody code:

 _currentSpeed.y += VerticalAcceleration * Time.deltaTime;
 _currentSpeed.y = Mathf.Clamp(_currentSpeed.y, -VerticalSpeedMax, VerticalSpeedMax);
 rigidbody2D.velocity = _currentSpeed * Time.deltaTime;
 

Cheers!

Comment
Add comment · Show 34 · 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 InvincibleCat · Feb 12, 2015 at 11:45 PM 0
Share

Did it work ?

avatar image FritzPeace · Feb 13, 2015 at 07:31 AM 0
Share

Got a couple of errors in line where the $$anonymous$$athf.Clamp works. First, shouldnt the -speedmax and speedmax be VerticalSpeed$$anonymous$$ax?

Second, I got these two errors. Will try to solve by miself, but maybe you can help me.

Assets/Scripts/Player$$anonymous$$ovement.cs(50,57): error CS1503: Argument #1' cannot convert UnityEngine.Vector2' expression to type float' Assets/Scripts/Player$$anonymous$$ovement.cs(50,57): error CS1502: The best overloaded method match for UnityEngine.$$anonymous$$athf.Clamp(float, float, float)' has some invalid arguments

avatar image FritzPeace · Feb 13, 2015 at 08:59 AM 0
Share

@InvincibleCat can you help me?

avatar image InvincibleCat · Feb 13, 2015 at 04:18 PM 0
Share

I've updated my answer. Can You show me your lines?

avatar image FritzPeace · Feb 13, 2015 at 04:24 PM 0
Share
 public float VerticalAcceleration = -2.0f;
 public float VerticalSpeed$$anonymous$$ax = 10.0f;
 private Vector2 _currentSpeed = Vector2.zero;

if (Jumping == false) { _currentSpeed.y += VerticalAcceleration Time.deltaTime; _currentSpeed.y = $$anonymous$$athf.Clamp(_currentSpeed, -VerticalSpeed$$anonymous$$ax, VerticalSpeed$$anonymous$$ax); rigidbody2D.velocity = _currentSpeed Time.deltaTime; if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)){ Jumping = true; } }

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Texture flickering (sniper scope reticle) 0 Answers

Distribute terrain in zones 3 Answers

Button Enabling/Disabling using Collision Triggers? 1 Answer

2D platformer- getting errors I don't understand (c#) 1 Answer


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