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 /
  • Help Room /
avatar image
0
Question by castyll · Sep 06, 2015 at 12:52 AM · c#rigidbody2d

Unity 2D - Terrain starts flipping when walking?!

Hello everyone, I got a bit of a stupid problem here. Basically I imported one asset as ground having a box collider (no settings changed) and being in a custom ground layer. Then I have a custom player layer where my Hero is with a circle collider, rigidbody2D, groundcheck etc ( see following pictures). Groundcheck works, my hero jumps only when placed on the ground, but when I start walking to the left or right, the ground goes crazy and flips around. When I stop walking, it basically gets thrown away. First, I thought I accidentally activated a rigidbody on it but no, I have absolutely no Idea what's going on. Here is the script and some pictures:

 using UnityEngine;
 using System.Collections;
 
 public class Controller : MonoBehaviour {
 
     public float speed;
     public float jumpspeed;
     Rigidbody2D rb;
     Animator anim;
     public Transform groundCheck;
     public LayerMask WhatIsGround;
     public float groundRadius;
     bool grounded;
 
 
 
     // Use this for initialization
     void Start () {
         rb = GetComponent<Rigidbody2D>();
         anim = GetComponent<Animator>();
     }
     
     // Update is called once per frame
     void FixedUpdate () {
 
 
         grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, WhatIsGround);
 
         if (Input.GetKey (KeyCode.LeftArrow)) {
 
             rb.velocity = new Vector2(-speed, rb.velocity.y);
             anim.SetInteger ("velc",1);
 
         }
 
 
         if (Input.GetKey (KeyCode.RightArrow)) {
             
             rb.velocity = new Vector2(speed, rb.velocity.y);
             anim.SetInteger ("velc",1);
             
         }
 
         if (Input.GetKey (KeyCode.Space)&& grounded==true) {
             
             rb.velocity = new Vector2(rb.velocity.x, jumpspeed);
         
 
         
         }
 
         if (Input.anyKey == false) {
             anim.SetInteger ("velc", 0);
         }
 
 
 
     
     }
 }
 


alt text alt text

Tell me if you need anything more, I hope anyone can help. Best regards

work1.png (41.3 kB)
work2.png (29.5 kB)
Comment
Add comment · Show 5
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 pako · Sep 06, 2015 at 09:19 AM 0
Share

If you set Gravity Scale = 0 on the player's rigidbody does it make a difference?

avatar image castyll · Sep 06, 2015 at 05:50 PM 0
Share

@pako i will try it when I get home but if I set the gravity to 0, doesn't it mean that i wont land on Ground again after jumping?

avatar image castyll · Sep 06, 2015 at 06:55 PM 0
Share

@Pako tried it out, ground stopped spinning but character walking and jumping didn't work clearly if gravity is off :\

avatar image pako · Sep 07, 2015 at 10:01 AM 0
Share

@castyll this was expected behavior. I just wanted to see if the Gravity Scale setting was part of the problem, and it is.

Well, you could simulate gravity by having a fallingspeed variable, with a value about equal to the jumpspeed. Then you'd decrease the 'y' component of rb.velocity when the player has finished the jump. I've got some code for this somewhere, and I could dig it up if you like.

However, the most interesting part is that I tried to replicate your ground flipping problem, and I just couldn't. I took some shortcuts to make things simpler, like no animation, and no layers. O$$anonymous$$, the player can jump any time, but the player can move left/right and jump, and the ground just stays put, no flipping.

So, since I can't replicate the problem, I can't give you an alternative to the gravity simulation solution, as I said above.

avatar image hexagonius · Sep 07, 2015 at 09:11 PM 0
Share

I agree with pako. from your screenshot there is no way that the ground moves an inch. biggest difference I see is the setting of the int on the animator.is it possible, that you accidentally animated the position of the player or something and there's keyframes trying to move it around?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

RigidBody2D velocity randomly drops to zero 1 Answer

How do I keep enemies (rigidbodies) from pushing each other? 1 Answer

Adding Rigidbody2d to gameobject removes it from game 0 Answers

AddForce rigidbody 2d not moving object 2 Answers

Zero drop force 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