简体   繁体   English

删除对象之间的空间

[英]Remove space between objects

So I made a simple 2D setting where you can move a block. 因此,我进行了一个简单的2D设置,您可以在其中移动块。 But I can not completely snap to another sprite (wall). 但是我不能完全捕捉到另一个精灵(墙)。

Screenshot: 屏幕截图: 在此处输入图片说明

Inspector settings wall: 检查器设置墙:

在此处输入图片说明

Inspector settings player: 检查器设置播放器:

在此处输入图片说明

PlayerMovement Script: PlayerMovement脚本:

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;
        }
    }
}

I have no idea what can create this space because the this is my first unity game. 我不知道该创造什么空间,因为这是我的第一个统一游戏。

I am almost sure it is because your sprite has this empty border. 我几乎可以肯定这是因为您的子画面具有此空白边框。 To fix this make sure that 'player' sprite is fully filled with white pixels or/and your 'wall' sprite. 要解决此问题,请确保“玩家”子画面完全被白色像素或/和您的“墙”子画面填充。 Basicly double check the images. 基本上仔细检查图像。

Also to fix this you could simply make collider slightly smaller to fit the image bounds. 为了解决这个问题,您可以简单地将对撞机稍微缩小一些以适合图像边界。

And finally make sure that collider corresponds with pixels you consider a body. 最后确保对撞机与您认为是物体的像素相对应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM