Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 DezZ1234 · Jul 19, 2015 at 07:14 PM · rotationjumpstopfallingdont

How can i make my 2D character not toppling over

Hello i am making a 2D game where my character is running to the right side over the screen and when he starts running he is falling over and my character is moving to the right side over the screen on his stomach i've tried a lot like freeze the z rotation and when i do that i can't jump with him maybe i made a mistake in my script i dont know pls. help me

here is my script:

using UnityEngine; using System.Collections;

public class PlayerScript : MonoBehaviour { public float maxSpeed = 10f; public float jumpForce = 700f; public bool grounded = false; public Transform groundCheck; private float groundRadius = 0.2f; public LayerMask whatIsGround;

 void Update () 
 {
     grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
     GetComponent<Rigidbody2D>().velocity = new Vector2 (1 * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);

     if (grounded && Input.GetKeyDown (KeyCode.Space)) 
     {
         GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 0);

         GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));

     
     }
 }

}

Comment
Add comment · Show 8
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 DezZ1234 · Jul 20, 2015 at 04:58 PM 0
Share

Hello ;)

I dont know how to keep my character run on his feet. Is there someone there know a way how to do it?

avatar image Cherno · Jul 20, 2015 at 05:00 PM 2
Share

Freezint z rotation should work. Why wouldn't you be able to jump with freezed z rotation?

Bonus tip: Use proper interpunctuation in your sentences so they are easier to read.

avatar image DezZ1234 · Jul 20, 2015 at 05:27 PM 0
Share

I dont know what there is wrong, when i click on my character and go under the Constraints and set a x in the Freeze rotation z i dont tripple over, but i can't jump i don't know why. Thanks for the bonus tip.

avatar image Cherno · Jul 20, 2015 at 06:55 PM 0
Share

Looks like the problem lies with the jumping code, then. If you post all the code related to jumping, perhaps someone can help you.

avatar image DezZ1234 · Jul 20, 2015 at 07:44 PM 0
Share

ok im' gonna do that, thanks

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotate a cube using touch 0 Answers

Rotation control (C#) 1 Answer

Trying to Add jump to this code. 1 Answer

How to stop MoveRotation when rigidbody is facing a specific euler angle 2 Answers

Does rotation increase velocity? 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