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 Liamh101 · Jul 25, 2013 at 11:22 PM · c#movementmovement scriptjumping

Movement Jumping Help

Hi!

I'm creating a 2D sidescroller. Right now I'm trying to create a movement script however I'm having a little trouble with the jumping. I've got my character to jump up however right now the character just aims for the ground and misses. (floats) Does anyone know how I can monitor how high the character can jump while not hamping movement (like found in CharacterController). I've posted the code bellow.

Thanks!

Code (written in C#)

void Update () {

 float speed = 20.0F;
 float jumpSpeed = 13.0F;
     
 //Here is where I will monitor key presses for player movement
 float translation = Input.GetAxis("Horizontal") * speed;
 float jumping = Input.GetAxis("Jump") * jumpSpeed; 
     
     translation *= Time.deltaTime;
     jumping *= Time.deltaTime;
     transform.Translate(translation, 0,jumping);    
 }
 
Comment
Add comment · Show 3
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 ikelaiah · Jul 25, 2013 at 11:42 PM 0
Share

What does "... the character just aims for the ground and misses. (floats)" mean? Also, what is Input.GetAxis("Jump")? Is "Jump" your vertical axis?

avatar image Liamh101 · Jul 25, 2013 at 11:52 PM 0
Share

When I let go of the space bar the character does not fall but stays on the say vertical level. With Jump that is my vertical axis and corresponds when I press the space bar.

avatar image gamerant · Jul 26, 2013 at 12:06 AM 1
Share

First of I'd say try changing Input.GetAxis("Jump") to Input.GetButtonDown("Jump").

And second you have no if statements in your code so the code doesn't know what logic to run and what to do. Create logic that can be executed for jumping and movement. Something like:

 if(Input.GetButtonDown("Jump"))
 {
    //The jumping logic goes here.
 }

If that isn't going well then I'd say try looking at a 2d runner tutorial for c#. Here is the link for it. http://catlikecoding.com/unity/tutorials/runner/

0 Replies

· Add your reply
  • Sort: 

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 a bubble level (not a game but work tool) 1 Answer

My character moves when i dont want to 0 Answers

How do i maintain the same speed in the air? 1 Answer

Player Jumps instead of moving forward 0 Answers

Character floats down after jumping 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