I’m a scholar in Austria. I’m engaged on a venture for varsity, the place we have now to do our personal first recreation with Unity. As a result of it’s the first time you utilize unity, always run in opposition to issues. Most of them, I already mounted. However this drawback caught me for just a few days. I am very sorry, I used so many photographs. Perhaps within the picture there’s some info that I didn’t give. The title of the collision map is “firststlayer_col”
That is what I’ve to date. My map is kind of giant. I used the tile palette to color them. I additionally used various kinds of layers. The land layer is principally fats or water. Along with that, I put the timber, that are seen within the following picture. I created a brand new Tilemap to show it right into a collision tilemap. I took a random mosaic and put it in all the things I need to have a collision.
I modified to the order of the layer to 10 for the collision tilemap, in order that I might see the place I’ve to place the mosaic to cease the participant, so he can not stroll on him or by way of him. After placing the mosaic in my desired location, I modified the order of the layer to 0 in order that I might not see it. I do not know if that could be a drawback or not. I’ve not discovered every other answer that can work for me. The collision tilemap has a Tilemap collider and the participant known as “South_0”, as a result of sprite I used for him, has a money colider and a inflexible physique. Every colider is 2D.
After beginning the appliance with the collision layer in 10. I can undergo it, cease within the place, the place the collision have to be as there isn’t any collision. After I change the order of the layer to 0, so it isn’t seen, I can stroll in the direction of the tree, however then my recreation begins to tremble and the participant turns. Then there’s some sort of collision, however when I attempt to undergo it, my recreation begins to tremble very sturdy after which my participant can stand in the course of the tree since there isn’t any collision. It seems to be very “buggy” and the participant turns in any course. I can not perceive how I could make the collision to forestall the participant from getting into the sector of my spot map collision with out making the participant go loopy and the complete display screen is stirred. I simply need the participant to cease in entrance of him, in order that there isn’t any technique to trouble him. I hope I defined my drawback so you may perceive it. Perhaps it is only a small small answer, however I could not discover any answer. The final picture is how my participant takes care of I ran in opposition to the tree with the collision map in layer 0. The participant mustn’t flip and easily go, 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;
}
change(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
}
```