Unity A* Pathfiding from a list - list

I'm developing a Dungeon Crawler style game and set a bunch of position objects as a "grid" for the player walk and stored them in a parent object, like a list. So I wanted to use that same list for the enemy moviment but after watching many A* Pathfinding tutorials for weeks I didn't managed to have any ideas of how to solve it since I'm not using a regular 2D grid. Here's a reference.

I took a look at your image, and you do in-fact have a grid. Just because you placed your objects does not mean you can calculate the "grid" for them from the list.
I would suggest you create a function that you call when your level starts.. and it iterates through the children of that object and generates a data structure that allows you to use A* to calculate pathing. You can use the transform.position of each object to determine it's relative placement/adjacency.

There is many ways you can do this. One suggestion would be creating an invisible collider with a trigger (can be on an empty GameObject) in different areas on your grid. Give the enemy a default velocity and attach a collider to the enemy and select the checkbox for trigger so when the enemy moves onto the trigger, you can call OnTriggerEnter (from a script attached to the enemy or the invisible collider GameObject) and make it change its movement. How you want to implement the AI is up to you.
edit as per comment
put invisible game objects positioned in your scene to how you would envision them being in an array from a birds eye view. In a script assign them to an array. Get the enemy to lerp between points in the array based on your ai algorithm. https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

Related

How to check hexagon pipe puzzle connection?

We're making a hexagon-shaped pipe-connecting puzzle game. Our code is based on Objects, and we are making the puzzle piece components by object functions we made. We don't have any physics yet either. Each pipe is able to move and rotate.
How can we write a function to check whether two or more pipes are connected?
What game engine do you use? I'd suggest keeping track of the pipe hexagons objects in a grid (a 2D array). Just imagine that every second row of the grid is shifted in by half the size of a hexagon). Then you can simply access all neighbors through that grid.
Eventually you need a function within the pipe tiles object like
bool canFlowTo(pipe_tile & other)
where you implement the right answer for each possible constellation of the pipe tile itself and the "other" tile.
To check where a pipe flows to, just call this function with all its neighbors in the grid.
Of course you can also approach this with a physics engine and not check correctness of the maze with code. For that just have colliders for each tile that have the right shape. For liquid physics you should definitely use some existing engine.
Oh and by the way, game questions that are not really related to a general C++ algorithm would probably fit better here: https://gamedev.stackexchange.com/

Unreal Engine 4 - Any suggestions on how I can I prevent my actor from "flying" by standing on top of an object while lifting it?

I have a code that changes the position of an object when grabbed to 100 units in front of the camera, this allows the player to stand on top of an object and pick it up causing him to fly towards wherever the camera is pointing.
Example: In this picture, I stood on top of a movable red rock. While on top I picked it up and moved my camera upwards which caused the rock to move to that position while carrying the actor. Because of this, I can quickly move to anywhere on the map by standing on top of an object and picking it up.
The skeletal mesh is unrelated to the grab function and the range of the grab is set to keep movable objects close to the skeletal mesh (like lifting this pebble) if that helps.
Any suggestions on how to fix this issue? Thanks in advance!
Assuming that your objects have some sort of toggle-able state that determines whether they can be picked up or not. One solution to the problem you are facing would be to cast a ray from the bottom of the player and if that ray hits an object that can be picked up, temporarily disable the ability to pick the object up. This introduces a new problem of stacking up two objects and moving the bottom object however. Alternatively you could also change objects so that when you are holding them, the collider is disabled on the object. There are many more ways you could go about solving this issue, but without knowing in detail what you are trying to accomplish by holding objects, it would be hard for anyone but yourself to choose the appropriate solution.

How to display a large scrolling level on a small viewport?

I asked a question yesterday about a problem I was having displaying a level in a C++ 2D GameBoy Advance game when the level is larger than the screen size. However, I may have been slightly too specific, and so I want to ask this more generally.
What is the simplest way to go about trying to display a scrolling level which is large (512x512 pixels) on a screen which is much smaller (240x160 pixels)?
A brief description of my code structure so far: I have a base class called Object which defines (x, y) position and a width and height, there is an Entity class which inherits from Object and adds velocity components, and a Character class which inherits from Entity and adds movement functions. My player is a Character object, and boxes I want the player to pick up are an array of Entity objects. Both the player and cubes array are members of the Level class, which also inherits from Object.
So far I have implemented a game which works very well when the level is the same size as the screen - all the objects' positions are stored relative to their position in the level. However, I am having serious trouble trying to work out how to display the objects in the correct place when the level is offset on the screen. I want the viewport to never extend out of the level, and if the viewport is not against the edge of the level, display the player in the middle of the screen.
Should I try to work it out using a couple of simple offset variables to move the background? If so, in what order should the offsets be calculated and applied? How would the offsets differently apply to the player and boxes? Or instead, should I try creating another Object as a member of the Level class for the viewport? How would I go about calculating the offsets using that?
Any advice provided wilil be greatly appreciated.

Cocos2d + Tiled + Teleportation (Tile Properties)?

So with Tiled, I can set Tile Properties directly on a tile before placing it on a map like so:
This is how I have done collision checking, by setting the collision property to 'true' and then checking the tile properties when moving a sprite.
However, I would like to add a 'teleport' tile. When the player walks on a specific tile, it takes them to a separate location.
The problem I am running into, is that when you set a property on a tile, you only get to set it once, and not on the tile instance. Meaning every tile would have the same teleport location.
Am I overlooking something? Is there a better way to go about doing this in Cocos2d in general?
You can use the object layer for this. Add an "object" (that's just a rectangle or point in Tiled) to the teleporter tile and use the object's properties to connect two locations together.
When you load the map you could walk over all objects to find the connecting objects. Then you know the two tile locations of the teleporter end points which you could store in a teleportation array. Every time your player moves to a new tile, check the teleportation array to see if the player is on one of the teleportation fields, and if he is, move him to the other teleportation tile.
Of course you could also check intersection with the object (rectangle) but since there's a chance that you might accidentally create an object (rectangle) that spans multiple tiles it seems more reliable to check these objects before the game starts.
Well this probably is the best way but it's what I've done. You could create a meta layer and have separate tiles for each teleporting pad. So when you check if the player is on teleportingpad1 you set the players location to receiverPad1 (which could be another tile, object in tiled, or just a point you set when you check for collisions). And you would just make another one e.g. teleportingpad2, teleportingpad3, etc. for more pads.

How to get collision detection among many objects to many players

I have 3-4 players in game and many objects (like stone, tree, cactus..etc). I have to find the collision detection between the objects and the players.
What is the easiest way with the speed performance to find the collision between objects and players.
If I pass player position for step movement to object class to find the collision detection it might be slow performance (each_step_of_player * all_objects).
Another idea I had is that I will write a schedule function for each object in Object class and for each schedule function call I will check collision with all player position ( Object * all_players). How is this idea regarding the speed performance?
Any another idea will be appreciate?
You can use grid-based collision detection.
Break your screen into grid of square cells, each cell at least as large as the largest object (this is important). Each object is assigned a cell, based on where the center of the object is. When you move the object, you reassign it to corresponding cell. Now you don't have to check an object against all other objects for collision, only against objects in its cell and adjacent cells.