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 D. Joe · Mar 29, 2016 at 05:10 PM · c#2dcollision

Space between sprites

So I made a simple 2D setting where you can move a block. But I can not completely snap to another sprite (wall).

Screenshot: scene screenshot

Inspector settings wall/player: Inspector settings

PlayerMovement Script:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour {
 
     public KeyCode moveUp;
     public KeyCode moveDown;
     public KeyCode moveLeft;
     public KeyCode moveRight;
 
     public float speed = 10f;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void FixedUpdate () {
 
         Vector2 v = rigidbody2D.velocity;
 
         if (Input.GetKey (moveUp)) {
             v.y = speed;
             v.x = 0;
             rigidbody2D.velocity = v;
         } else if (Input.GetKey (moveDown)) {
             v.y = speed * -1;
             v.x = 0;
             rigidbody2D.velocity = v;
         } else if (Input.GetKey (moveRight)) {
             v.x = speed;
             v.y = 0;
             rigidbody2D.velocity = v;
         } else if (Input.GetKey (moveLeft)) {
             v.x = speed * -1;
             v.y = 0;
             rigidbody2D.velocity = v;
         } 
         else 
         {
             v.x = 0;
             v.y = 0;
             rigidbody2D.velocity = v;
         }
     }
 }

These are the files I'm using: Player: https://onedrive.live.com/redir?resid=451ADC2A2ED2D0E7!108&authkey=!AAimm1ss1vE_ZfA&v=3⁢hint=photo%2cpng Wall: https://onedrive.live.com/redir?resid=451ADC2A2ED2D0E7!109&authkey=!AAxqJwKjBiS2n8A&v=3⁢hint=photo%2cpng

I have no idea what can create this space because the this is my first unity game. Thanks in advance!!

screenshot.jpg (141.6 kB)
ohfbh2r.png (12.5 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Abhiroop-Tandon · Mar 30, 2016 at 11:12 AM

Make sure there is no extra space in the sprite that is causing this issue to be sure. If there is no space then what you can do is press V when you are in the 'moving the object ' mode and hover at one corner of your object. You will see some kind of a pointer over there. If you drag from that pointer you can snap it at any edge of the other object with utmost precision. i hope it makes sense. Just try it and you will understand what i am trying to say. Also make sure the collider is not bigger than your sprite.

PS- You need a mouse for this, i dont know why it doesnt works on the touchpad of the laptop.

Comment
Add comment · Show 6 · 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 D. Joe · Mar 30, 2016 at 11:37 AM 0
Share

Hi, I can snap the player to the wall when I am in the scene mode, but the problem occurs when I play the game and try to move the square to a wall, I added the sprites I used in my post and there is no space left.

When I play the game and then try to touch the wall I can see the colliders are not touching each other in the scene view as you can see here: http://prntscr.com/alyntu

i hope you can help me as I am very frustrated!

avatar image Abhiroop-Tandon · Mar 30, 2016 at 11:40 AM 0
Share

Did you double check the colliders on both the player and the wall ?? Try reducing their size and see what happens. Dont worry making a game is a long and intense process. Just hang in there and you will do it.

avatar image D. Joe Abhiroop-Tandon · Mar 30, 2016 at 11:58 AM 0
Share

Reducing the size does not help. I checked the colliders and they are at the right point. But I they can;t touch each other/ As you can see in my screen shot (The green lines are the colliders). Thanks for your help I highly appreciate it!

avatar image Abhiroop-Tandon Abhiroop-Tandon · Mar 30, 2016 at 12:59 PM 0
Share

Just one quick thing, is your player following physics ?? If its not then why do you have a rigidBody on it?

Does your player needs to be affected by gravity? You have no parameters set for that under the rigidbody component. Try adding mass and gravity to get it down on the ground.

If your player does not needs to be affected by gravity then it should be kinematic. You should check that 'is $$anonymous$$inematic' box under the rigidbody component.

Try out these things and let me know.

avatar image D. Joe Abhiroop-Tandon · Mar 30, 2016 at 07:04 PM 0
Share

Hi, I need the rigid body to detect Collision. But when I have set the rigidbody to use gravity it also shows this space. Also with other colliders like Circle colliders and stuff. But when I tick the kinematic option it also shows me the space.

Show more comments

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

149 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

Related Questions

How to show an object when collided with 0 Answers

How do I get my character to collide with an object, he dies, and respawnee at the beginning of the map? 1 Answer

[c sharp] why isn't my player dying when it touches the truck? 1 Answer

Collision between two prefabs not being detected 0 Answers

Stuck inside of Composite Collider when using Platform Effector 2D 2 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