Unreal Engine 5 How To Have a Non-player pawn take controller inputs - controls

I have two character blueprints in a level that spawn on opposite sides of a room, and both should move as mirrors of each other. However, only one will move even though both should be getting the controller input. The first image is a screenshot of the player, and the second is a screenshot of the other character.
player
other one

Related

How to determine which room a player is in?

I am working on a 2D platforming video game. The rooms are divided into areas, which are essentially intangible hitboxes. The camera is bounded by these hitboxes, and will not show what is in the next room until the player transitions into a new one.
If the player walks from one room to another, the camera pans to the new room. Panning the camera pauses the physics engine to ensure the player cannot break the game or die while the camera is in it's animation.
My problem exists in the fact that the player doesn't belong to a single room at a time since the player's hitbox is 2D. When the player moves between rooms, for a short period of time, the hitbox overlaps two rooms at once.
This means, that if I pan the camera when the player enters a new room, the player can partially enter the new room (while still remaining in the old room), then go back into the old room, which doesn't pan the camera back because they never technically entered the old room. How could they have entered it? They never left it!
This also means, that if I pan the camera upon the player leaving a room, the player can partially enter a new room, then leave the new room that they never fully entered. This means that the camera pans to the same room that it was already in (this plays a weird animation, and pauses the physics engine).
How can I determine what room the camera should pan to?
I have access to:
When the player enters a room, and which room.
When the player exits a room, and which room.
All rooms, and the variables of all rooms.
func _on_room_area_2d_body_entered(body): # body enters room
if body.is_in_group("junko"): # is this the player?
player_inside = true
junko.pan_camera(self) # pan the camera
func _on_room_area_2d_body_exited(body): # body exits room
if body.is_in_group("junko"): # is this the player?
player_inside = false
Just because the rooms are big, it does not mean they have to keep track of what is inside of them. Instead, the character can keep track of inside of which rooms it is.
If you want to detect areas, you need an area. So make an area child of your player character… Which I'll call locator. Then set the locator up to detect the areas that make up the rooms. That means that locator must be monitoring, and the rooms must be monitorable. And also the collision layer of the rooms must overlap the collision mask the locator.
Then you can use area_entered and area_exited (notice these signals are called area_* not body_*).
You might find it easier to call get_overlapping_areas on the detector in _physics_process and then from the result pick the rooms.
for entry in $locator.get_overlapping_areas():
prints(entry)
Then perhaps only pan the camera when there is only one room and it is not the one where the camera is currently at, or some similar rule.
In fact, you don't need a detector. You can do what "Yakov Galka" suggested in the comments and ask Godot what areas are in a particular point.
You do that with intersect_point:
var result:Array = get_world().direct_space_state.intersect_point(
global_position,
32,
[],
2147483647,
false,
true
)
And that returns an Array with the results. So you can iterate like this:
for entry in result:
prints(entry.collider)
To explain the parameters:
First you pass the point coordinates global_position.
Second you pass how many result you want at most (32 in this case).
Then you pass an array with elements you want to exclude (none in this case: []).
Then the collision mask (2147483647 is all the bits)
Then if you want bodies (no, so false)
And finally if you want areas (yes, so true).
Please notice that even though this is only checking a single point, it does not guarantee you have a single result (you can have multiple if the areas overlap).

Is it possible to deduce the tiles each player has just by viewing the tiles played for an entire Scrabble game?

Given as input the tiles used by each player for every turn and the tiles each player has left at the end of the game, disregarding the possibility of swapping all of the tiles for a turn, is it possible to deduce the tiles each player has for each turn of a game of Scrabble?
Just to clarify, you have full knowledge of all of the plays, so you know exactly which plays make every word. The question is, can you can work backwards from the end of the game with complete play information to know the tiles each player has earlier in the game?
No, it's not possible. Most layouts are not susceptible to retrograde analysis: there are multiple draws and plays that will lead to the same board configuration. For instance, given only a single word in the middle "PATER", you have no idea whether that was a single play or up to five plays.
Your second question is significantly off-topic (too broad) for Stack Overflow.
Got it; my mistake earlier.
No, the unplayed tiles are not generally susceptible to retrograde analysis. Consider merely the first three plays of ASTER, DOU(R), and (S)HOWBOAT. Of those seven letters player 1 just laid, you have no way of knowing which two were in the original rack, and which were drawn after playing ASTER.
The only time you know exactly what seven tiles a player had at a given turn is when all seven are revealed on the play (or end of game).

A better way to roll dice

I have a game that requires the player to roll two die. As this is a multiplayer game, the way I currently do this is have 6 animations (1 for each die's outcome). When the player clicks a button, it sends a request to my server code. My server code determines the die's outcome and sends the results to the client. The client then plays the corresponding animations.
This works ok, but has some issues. For instance, if the server sends back two of the same values (two 6's, for example) then the animations don't work correctly. As both animations are the same, they overlay each other, and it looks like only one die was rolled.
Is there a better way to do this? Instead of animations, using "real" dice? If that's the case, I always need to be sure to "pre-determine" the outcome of the dice roll, on the server. I also need to make sure the dice don't fall off the table or jostle any of the other player pieces on the board.
thanks for any ideas.
The server only needs to care about the value result, not running physics calculations.
Set up 12 different rolling animations:
Six for the first die
Six for the second die
Each one should always end with the same modeled face pointing upwards (the starting position isn't relevant, only the ending position). For the latter steps you'll probably want to adjust the model's UV coordinates to use a very tall or very wide texture (or just a slice of a square one). So not like this but rather all in a line 1-2-3-4-5-6.
The next step is picking a random animation to play. You've already got code to run a given animation, just set it to pick randomly instead of based on the die-roll-value from the server:
int animNum = Mathf.Floor(Random.Next()*6);
Finally, the fun bit. Adjusting the texture so that the desired face shows when the animation is done. I'm going to assume that you arrange your faces along the top edge of your square texture. Material.SetTextureOffset().
int showFace = Mathf.Floor(Random.Next()*6); //this value should come from the server
die.renderer.material.SetTextureOffset(1f/6 * showFace,0);
This will set the texture offset such that the desired face will show on top. You'll even be able to see it changing in the inspector. Because of the UVs being arranged such that each face uses the next chunk over and because textures will wrap around when reaching the edge (unless the texture is set to Clamp in its import settings: you don't want this here).
Note that this will cause a new material instance to be instantiated (which is not very performant). If you want to avoid this, you'll have to use a material property block instead.
You could simulate the physics on the server, keep track of the positions and the orientations of the dice for the duration of the animation, and then send the data over to the client. I understand it's a lot of data for something so simple, but that's one way you can get the rolls to appear realistic and synced between all clients.
If only Unity's physics was deterministic that would be a whole lot easier.

Plat former Game - A realistic path-finding algorithm

I am making a game and i have come across a hard part to implement into code. My game is a tile-bases platformer with lots of enemies chasing you. basically, in theory, I want my enemies to be able to, every frame/second/2 seconds, find the realistic, and shortest path to my player. I originally thought of A-star as a solution, but it leads the enemies to paths that defy gravity, which is not good. Also, multiple enemies will be using it every second to get the latest path, and then walk the first few tiles of it. So they will be discarding the rest of the path every second, and just following the first few tiles of it. I know this seems like a lot, to calculate a new path every second, all at the same time, if their is more than one enemy, but I don't know any other way to achieve what i want.
This is a picture of what I want:
Explanation: The green figure is the player, the red one is an enemy. the grey tiles are regular, open, nothing there tiles, the brown tiles being ones that you can stand on. And finally the highlighted yellow tiles represents the path that i want my enemy to be able to find, in order to realistically get to the player.
SO, the question is: What realistic path-finding algorithm can i use to acquire this? While keeping it fast?
EDIT*
I updated the picture to represent the most complicated map that their could be. this map represents what the player of my game actually sees, they just use WASD and can move around and they see themselves move through this 2d plat-former view. Their will be different types of enemies, all with different speeds and jump heights. but all will have enough jump height and speed to make the jumps in this map, and maneuver through it. The maps are generated by simply reading an XML file that has the level data in it. the data is then parsed and different types of tiles are placed in the tile holding sprite, acording to what the XML says. EX( XML node: (type="reg" graphic="grass2" x="5" y="7") and so the x and y are multiplied by the constant gridSize (like 30 or something) and they are placed down accordingly. The enemies get their frame-by-frame instruction from an AI class attached to them. This class is responsible for producing this path and return the first direction to the enemy, this should only happen every second or so, so that the enemies don't follow a old, wrong path. Please let me know if you understand my concept, and you have some thought/ideas or maybe even the answer that i'm looking for.
ALSO: the physics in this game is separate from the pathfinding, they work just fine, using a AABB vs AABB concept (the player and enemies also being AABBs).
The trick with using A* here is how you link tiles together to form available paths. Take for example the first gap the red player would need to cross. The 'link' to the next platform (aka brown tile to the left) is actually a jump action, not a move action. Additionally, it's up to you to determine how the nodes connect together; I'd add a heavy penalty when moving from a gray tile over a brown tile to a gray tile with nothing underneath just for starters (without discouraging jumps that open a shortcut).
There are two routes I see personally: running a quick prediction of how far the player can jump and where they'd jump and adjusting how the algorithm determines node adjacency or accept the path and determine when parts of the path "hang" in the air (no brown tile immediately below) and animate the enemy 'jumping' to the next part of the path. The trick is handling things when the enemy may pass through brown tiles in the even the path isn't a parabola.
I am not versed in either solution; just something I've thought about.
You need to give us the most complicated case of map, player and enemy behaviour (including jumping up and across speed) that you are going to either automatically create or manually create so we can give relevant advice. The given map is so simple, put the map in an 2-dimensional array and then the initial player location as an element of that map and then first test whether lower number column on the same row is occupied by brown if not put player there and repeat until false then same row higher column and so on to move enemy.
Update: from my reading of the stage generation- its sometime you create- not semi-random.
My suggestion is the enemy creates clones of itself with its same AI but invisible and each clone starts going in different direction jump up/left/right/jump diagonal right/left and every time it succeeds it creates a new clone- basically a genetic algorithm. From the map it seems an enemy never need to evaluate one path over another just one way fails to get closer to the player's initial position and other doesn't.

Time delays and Model View Controller

I am implementing a turn based game, there are two sides and each side has several units, at each specific moment only one unit can move across the board.
Since only one unit can move at a time, after i figure out where it should go, as far as the simulation is concerned it Can instantly be teleported there, but playing the game you would want to see the unit moving so that you realise who moved and where he went.
The question is, would you put the movement algorithm (eg interpolating between 2 points in N seconds) in the model and then have the view show the unit in the interpolated position without even knowing that it is moving, or teleport the unit and notify the view that it should show the unit moving as best as it wants.
If you would take the second approach, how would you keep the simulation from running too far ahead of the view, would you put the view in command of resuming the simulation after the movement ended?
Thanks in advance, Xtapodi.
Ah, yet another example that reminds us that MVC was never originally designed for real-time graphics. ;)
I would store the current position and the previous position in the model. When the object moves, the current position is copied into the previous position, the new position is copied into the current position, and a notification is sent to the view that the model has changed. The view can then interpolate between the old and the new position accordingly. It can speed up, slow down, or even remove the interpolation entirely based on the specific view settings, without requiring any extra data to be stored within the model.
Rather than storing the current position and the previous position, you could instead just store the last move with each unit, and the move itself contains the previous position. This is probably more versatile if you ever need to store extra information about a move.
What you probably want is to have the unit image move each frame. How far to move the image each frame is similar to your interpolation.
unitsPerSecond = totalUnits / (framesPerSecond * totalSeconds)
So if I want to move an image from position 0 to position 60 in 2 seconds and my framerate is 30, I need to move 60 units in 60 frames, therefore my speed is 1. So each frame, I move the image 1 unit, and if moving the unit will take me beyond my destination, simply set my location to my destination.

Resources