Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 orchard800 · Nov 29, 2015 at 03:06 AM · rigidbody3dcolliderssprites

2D sprite with rigidbody - movement stalling in 3D environment

As a learning experience, I'm trying to put together something that looks like Legend of Dungeon, which is a 3d isometric (I've read some the developers blog posts so know it is) world with 2d sprites.

I've given my empty player object a sprite renderer and changed the material to sprite-diffuse for dynamic lighting. I'm moving the player with transform.translate. I've got some coloured lights in there and it looks and works smoothly. Apart from I have no collision control yet.

So... I add a 3d collider (which I've read elsewhere is the way to do it), but it's not actually colliding with my 3d scenery (which at present are just cubes with box colliders) it just passes through them .

So I realise at this point that my player also needs a rigidbody, right? So I do that and change my code to use:

 rBody.velocity = new Vector3(horizontal * speed,0,0);

in FixedUpdate(). Where horizontal is GetAxis or GetAxisRaw. All as per the Unity docs.

Problem: it moves as before but randomly freezes the motion, as if the player has become stuck. it only gets moving again with random wiggling of the horizontal axis. I've tried several times removing and recreating the problem and it happens every time. There aren't any other factors or assets in there to affect project.

What am I doing wrong??? Alternatively, how should I be handling movement and collisions in this scenario?

Comment
Add comment · Show 1
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 orchard800 · Nov 29, 2015 at 10:42 AM 0
Share

Ok, so after more trial and error (and a lot of coffee)..

By replacing the individual box colliders on the cubes that make up the floor, with just one big 'floor' collider the problem goes away. But, when I put two of these new floor pieces together, the player sometimes gets stuck passing over the two, but only then.

Is this expected? Is it a bug? Any opinion on this would be gratefully received.

2 Replies

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

Answer by orchard800 · Dec 06, 2015 at 03:33 PM

Here's the official answer from Unity.

I logged it as bug and after looking into it, this is the reply I received. I thought I would post here as I have read many posts about users having similar issues, but they never seem to find an answer. Here's why:

It is not designed in any way to be like this, but there is no good way to fix it besides changing world geometry. In fact, this is a long standing issue. Quote from what one of our developers said:

"Putting colliders side-by-side may visually seem as if they're continuous from the gizmo rendering POV but from a numerical perspective, it isn't a continuous surface. This causes the colliders to catch. Sliding a collider over this surface (such as a Box) would cause the collider to catch on an edge. This is a well know problem and isn't a bug, it's just the way the solver works."

You could also check this site, even though it is covering from a 2D standpoint, the main idea stays the same.

Comment
Add comment · 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
0

Answer by Aggrojag · Nov 29, 2015 at 04:33 AM

I personally would use 2D colliders for a legend of dungeon type of game, as this is what I'm comfortable with. When in 2D you should still use velocity (via the rigidbody2D component). The reason for using velocity rather than translation is translation doesn't work as closely with the physics that Unity has created.

As far as possible problems, I'd imagine your Z axis could be off, possibly the collider isn't set up properly, or maybe even the collider itself is rotating. Without knowing a fair bit about what you're doing, it's really hard to say. Perhaps showing how your scene is set-up along with full movement code would result in a better answer.

PS: You say random wiggling, so I'm thinking this is a rotation issue. Lock rotation on the axis causing you trouble and see if that works. If not, repost with more information please.

Comment
Add comment · Show 5 · 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 orchard800 · Nov 29, 2015 at 05:03 AM 0
Share

Hi @PianoHandsThePerson and thanks for the quick answer.

Ok, this may be a dumb question, but in Legend of Dungeon, the player can move in 3 dimensions (up/down, left/right and up and down the stairs), so would a 2d collider and rigidbody allow me to do that? ie wouldn't that allow the player to walk through the back wall and off the platform?

$$anonymous$$y scene is simply a 4x6 row of cubes(vert collision). Sat on top of that is my player and a single cube (to test horiz coll.). He falls in to place with gravity, to make sure he's sat on top of the floor.

$$anonymous$$y code:

 using UnityEngine;
 using System.Collections;
 
 public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour 
 {
     public float speed = 5f;
     Rigidbody rBody;
 
     float horizontal;
     float vertical;
 
     void Start () 
     {
         rBody = GetComponent<Rigidbody>();
     }
 
     void Update () 
     {
         horizontal = Input.GetAxis("Horizontal");
     
     }
 
     void FixedUpdate()
     {
 
         rBody.velocity = new Vector3(horizontal * speed,0,0);
     }
 
 }

I can move the player around for a few seconds in any sequence of left and right movement. Interestingly, since I cleaned up this code to paste here, I removed the vertical axis movement and its now impossible to get it going again once it freezes and you have to stop the game. It's as if Unity is freezing but thats not the case and my PC's resources only calm down once it freezes, so it's not like its trying to compute some heavy maths or anything.

The player's rigidbody is already set up with constrained rotation on all axes, but I like that line of inquiry...

I will try the 2d collider in the meantime. but if you could elaborate that would be great! Thanks!

Update: I have added a 2d collider and 2d rigidbody but now he just falls straight through the floor.

avatar image Aggrojag orchard800 · Nov 29, 2015 at 05:15 AM 0
Share

2D colliders only act on other 2D colliders. EDIT: A$$anonymous$$A, make sure your ground is using a 2d Collider

As far as how that would work on a 2D plain, your "up and down" would be a change in the Y Axis, then you would just unrestrain that upon using a ladder. You would want to be removing "use gravity" as well from the rigidbody(2d), allowing for change in Y velocity, and restraining the yPosition (and zeroing out YVelocity once reaching this position).

If you're using a 2D rigidbody, it changes the call to rBody = GetComponent(); - $$anonymous$$ake sure you're not getting an error.

Beyond that, I see no error in the code that would cause this.

Showing how the scene is set up, including both the player and the ground object would help immensely.

avatar image orchard800 Aggrojag · Nov 29, 2015 at 05:47 AM 0
Share

Wouldn't using 2d colliders stop characters passing each other on the x axis even if they had different z values. ie if one tried to pass behind the other, they would collide, right?

Here are some pics of the scene with relevant details presented in the inspector:

alt text alt text

2.png (164.9 kB)
1.png (153.6 kB)
avatar image orchard800 · Nov 29, 2015 at 10:21 AM 0
Share

Ok, so going back to the original problem: Through further testing I have found that un-freezing rotation on the z axis (although the character does roll) OR turning off gravity on the rigidbody, completely stops the stalling problem stops, leading me to agree that it's something to do with it trying to rotate or somehow getting stuck on the floor.

But how to solve this?

avatar image Aggrojag orchard800 · Nov 29, 2015 at 06:15 PM 0
Share

You're right about the z axis not mattering, and it stopping things. In this type of game, your Y Axis would function as your z axis. It may not be as effective as a 3D environment, but that's the approach I personally would start out with.

As far as possible problems, try creating a new box, make it rather large, and test on that. $$anonymous$$y feeling is that all the small boxes either have gaps, or are offset.

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

34 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 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

collision with floor fails when jumping,Player falls through floor 3 Answers

A position locked hinge joint with drag and no gravity? 1 Answer

Negate a Single Collision 1 Answer

OnMouseDown not firing if character isn't touching ground 0 Answers

Colliders going through Colliders? 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