• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to change an objects position and rotation inside a script? 0 Answers

Stop moving rigidbody but don't stop rotating 1 Answer

Fall time and Unfreezerotation on a rigidbody. 1 Answer

Stop the script - problem with myObject's rotation. 0 Answers

rigidbody player jump automatically. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges