i’m a scholar in austria. I’m engaged on a mission for college, the place we now have to make our personal first sport with unity. As a result of it’s the first time utilizing unity, i consistently run in opposition to issues. Most of them, i mounted already. However this drawback received me caught for just a few days now. I’m very sorry, that i used that many photos. Perhaps within the image there may be some data i didn’t offer you. The identify of the collision map is “FirstLayer_Col”
That is what i’ve received up to now. My map is fairly huge. I used the tile palette, to color them in. I additionally used several types of layers. The bottom layer is generally gras or water. On high of that, i put the timber on, that are seen within the subsequent image. I created a brand new tilemap to make it a collision tilemap. I took a random tile and put it on every little thing i wish to have a collision on.
I modified to order of layer to 10 for the collision tilemap, so i may see the place i’ve to place the tile to cease the participant from, so he cant stroll over or by way of it. After i put the tile on my needed location, i modified the order of layer again to 0 so i couldnt see it anymore. I dont know if that may be a drawback or not. I’ve not discovered every other answer that labored for me. The collision tilemap has a tilemap collider and the participant named “South_0” ,due to the sprite i used for it, has a field collider and a rigidbody. Each collider is a 2D one.
After i begin the applying with the collision layer on 10. I can undergo it, stand on the place, the place the collision must be as there isn’t a collision. When i modify the order of layer to 0, so it isn’t seen, i can stroll to the tree, however then my sport begins to shake and the participant rotates. Then there may be some kind of collision, however when i attempt to undergo it, my sport begins to shake very robust after which my participant can stand in the course of the tree as there’s no collision. It seems very “buggy” and the participant rotates in any route. I cannot determine, how i could make the collision to cease the participant from getting into the sector of my tilemap collision with out making the participant go loopy and make the entire display screen shake. I simply need the participant to cease in entrance of it, in order that there isn’t a manner of bugging by way of it. I hope i defined my drawback so you may perceive it. Perhaps it’s only a small, little repair, however i couldn’t discover any answer. The final image is how my participant takes care of i ran up in opposition to the tree with the collision map on layer 0. The participant mustn’t rotate and simply go, up, down, left, proper.
My Code for my Participant:
utilizing UnityEngine;
utilizing System.Collections;
public class PlayerMovement : MonoBehaviour {
Path currentDir;
Vector2 enter;
bool isMoving = false;
Vector3 startPos;
Vector3 endPos;
public float t;
public Sprite northSprite;
public Sprite eastSprite;
public Sprite southSprite;
public Sprite westSprite;
public float walkSpeed = 0.5f;
public bool isAllowedToMove = true;
void Begin()
{
isAllowedToMove = true;
}
void Replace () {
if(!isMoving && isAllowedToMove)
{
enter = new Vector2(Enter.GetAxis("Horizontal"), Enter.GetAxis("Vertical"));
if (Mathf.Abs(enter.x) > Mathf.Abs(enter.y))
enter.y = 0;
else
enter.x = 0;
if(enter != Vector2.zero)
{
if(enter.x < 0)
{
currentDir = Path.West;
}
if(enter.x > 0)
{
currentDir = Path.East;
}
if(enter.y < 0)
{
currentDir = Path.South;
}
if (enter.y > 0)
{
currentDir = Path.North;
}
swap(currentDir)
{
case Path.North:
gameObject.GetComponent<SpriteRenderer>().sprite = northSprite;
break;
case Path.East:
gameObject.GetComponent<SpriteRenderer>().sprite = eastSprite;
break;
case Path.South:
gameObject.GetComponent<SpriteRenderer>().sprite = southSprite;
break;
case Path.West:
gameObject.GetComponent<SpriteRenderer>().sprite = westSprite;
break;
}
StartCoroutine(Transfer(remodel));
}
}
}
public IEnumerator Transfer(Remodel entity)
{
isMoving = true;
startPos = entity.place;
t = 0f;
endPos = new Vector3(startPos.x + System.Math.Signal(enter.x), startPos.y + System.Math.Signal(enter.y), startPos.z);
whereas (t < walkSpeed)
{
t += Time.deltaTime * walkSpeed * walkSpeed;
entity.place = Vector3.Lerp(startPos, endPos, t);
yield return null;
};
isMoving = false;
yield return 0;
}
}
enum Path
{
North,
East,
South,
West
}
```