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 bobbobus05 · Aug 24, 2020 at 10:59 AM · c#collisiongameobjectphysics2dgameobjects

unity2D colliders not working properly,,Unity2D Colliders don't seem to be working HELP PLEASE!

Hi, so me and my friend are beginners to unity and we decided to create a simple 2D game where the players and enemies are sprites formed as cubes(2D) and it is a grid based movement system(so the sprites moves one tile at a time(using tilemaps). we have the same movement script to both the player and the enemy because we want them to move the same at the same time(that to say, if we press down they both go down even if they arent on the same tile) its kind of the movement system in 2048 where all the cubes moves the same direction. well that out of the way we just cant seem to get the colliders to work between the enemies and the player, but it works on walls etc because on the walls we have given them a specific Layer and that works, but if i do the same on the enemis and the player, they dont go into eachother and merge, which we want but then theres another probelm where if they are over and under eachother and you for example move down, the player/enemy at the bottom only goes down and not the on at the top, and as i said we wanted to have them move the same direction and not merge. but if i dont have the layers on the player and enemy this problem don't occur but then instead they merge. we have follow ALOT of tutorials on collision etc, but nothing works. we have box colliders on both objects (IS TRIGGER is off) and we have rigidbodys on both, now idk if i have to code for it to work but almost every tutorial showed that it isn't needed. we have these movepoints attatched to the player and enemy where the movepoint move and the sprites go there.

Here is the movement script attacherd to both the enemy and the player:

public class Movement : MonoBehaviour { public float moveSpeed = 5f; public Transform movePoint;

 public LayerMask whatStopsMovement;
 public LayerMask FinishPlayer;

public Transform movePoint; public float moveSpeed = 5f;

 GameObject CheckPlayerWin;

 Rigidbody2D rb;
 
 // Start is called before the first frame update
 void Start()
 {
     movePoint.parent = null;
 }


 void Update() 
 {

     transform.position = Vector3.MoveTowards(transform.position, movePoint.position, moveSpeed * Time.deltaTime);

     if(Vector3.Distance(transform.position, movePoint.position) <= .05f)
     {
         if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) == 1f)
         {
             if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f), .02f, whatStopsMovement))
             {
                 movePoint.position += new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f);
             }
         } else if (Mathf.Abs(Input.GetAxisRaw("Vertical")) == 1f)
             {
                 if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f), .02f, whatStopsMovement))
                 {
                   movePoint.position += new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f);
                 }
             }
     }        
     
 }

}

Thanks for your time and it would be appreciated if we could get help :)

Comment
Add comment · Show 2
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 logicandchaos · Aug 26, 2020 at 12:43 AM 0
Share

Put in debug logs to find out what is happening, where the code is going.

avatar image bobbobus05 logicandchaos · Aug 29, 2020 at 04:51 PM 0
Share

So when i add in debug logs it prints in the console where the player and enemy moves, wheter it's vertical or horizontal. it obviously prints when i move and they still do when they have merged(which they're not supposed to do in the first place) so that works but i don't know how to keep them from merging, if you need screenshots or something of the settings attached to the player and enemy, tell me.

thanks in advance!

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

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

If Check Colliding GameObject Variable 1 Answer

Unity 2D - How do I add the velocity and direction of an object to another object? 2 Answers

Specific GameObject Collision Issue 1 Answer

How to calculate angular velocity after a collision? 0 Answers

How to stop object from going through walls. 4 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