Hello
So im trying to make a collision with vector2int, i have tried to do some research on this or think of ideas on making colliders with vector2int but i havent found one
Hello
So im trying to make a collision with vector2int, i have tried to do some research on this or think of ideas on making colliders with vector2int but i havent found one
Hello emir_ulusoy_49,
Could you please be more specific as to what your goals are? - as in, what would you like to “collide” with this Vector2int? I’m also assuming you are trying to check for collision every frame or so? The more information you can provide, the better.
Hi @WolverineLight
Thank you for answering
Well my goal is to make an algorithm pathfinding project and im making use of generating grids (and im generating the grid with 1 single sprite that is going to be also 4 other sprites), that is Ai (thats gonna be the pathfinding) and Button ( thats gonna be pressed, and when its being pressed a door opens), Door is the end of the game ( basically the goal), then a Chest ( that is gonna be used for pusing it to button to open the door).
the problem is, is that im using Vector2Int fields, but i cant use Vector2Int in OnTriggerEnter2D method or i cant assign rigidbody or box collider seperatly (so i cant for exemple assign to the chest a box collider then the ai to have collider and then rigidbody) because im using 1 sprite for all of them.
here is some code, so it can be easier to understand hopefully
(this is the fields im using)
`
public CellType grid; // 2D array list, this generates the amount of elements
public int gridWidth; // This divides the amount of number it is type in
public int gridHeight => grid.Length / gridWidth; //Calulates the height of the grid
public Vector2Int Player; // Player position in 2D
public Vector2Int Enemy; // Enemy position in 2D
public Vector2Int GoalDoor; // Goal position in 2D
public Vector2Int Button;
public Vector2Int Chest;
public bool playerTurn; // This checks if its player turn or not
public bool hasPressedbutton;
`
here is a script for in game
`
using System;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using Object = UnityEngine.Object;
[Serializable]
public class GameView : MonoBehaviour
{
public BoardPiece BoardPiecesPrefab;
private List<BoardPiece> boardPieces = new List<BoardPiece>(); //Created a list of boardPieces
private State sttate;
public void UpdateView(State state)
{
foreach (var boardPieces in this.boardPieces) //Destroyes old pieces?
{
Destroy(boardPieces.gameObject);
}
boardPieces.Clear();
for (int i = 0; i < state.gridWidth; i++)
{
for (int j = 0; j < state.gridHeight; j++)
{
var boardPiece = Instantiate(BoardPiecesPrefab, new Vector3(i, j), Quaternion.identity);
boardPiece.sprite.color = Color.green;
boardPieces.Add(boardPiece);
}
}
var boardEnemy = Instantiate(BoardPiecesPrefab, new Vector3(state.Enemy.x, state.Enemy.y, -0.01f), Quaternion.identity); //Creates Enemey
boardEnemy.sprite.color = Color.red;
boardPieces.Add(boardEnemy);
var boardPlayer = Instantiate(BoardPiecesPrefab, new Vector3(state.Player.x, state.Player.y, -0.01f), Quaternion.identity); //Creates Player
boardPlayer.sprite.color = Color.cyan;
boardPieces.Add(boardPlayer);
var Button = Instantiate(BoardPiecesPrefab, new Vector3(state.Button.x, state.Button.y, -0.01f), Quaternion.identity); // Creates Goal
Button.sprite.color = Color.yellow;
boardPieces.Add(Button);
var Goal = Instantiate(BoardPiecesPrefab, new Vector3(state.GoalDoor.x, state.GoalDoor.y, -0.01f), Quaternion.identity); // Creates Goal
Goal.sprite.color = Color.magenta;
boardPieces.Add(Goal);
var chest = Instantiate(BoardPiecesPrefab, new Vector3(state.Chest.x, state.Chest.y, -0.01f), Quaternion.identity); // Creates Goal
chest.SpriteChest.color = Color.blue;
boardPieces.Add(chest);
}
}
`
i tried to get a insert a image so it can be more clearify on how the game looks but idk how this site works