Switch turns between the Player and AI in Unity - unity3d

I've recently started using Unity for a resource management stealth game. The stealth part is turn based, similar to Hitman Go. I have a simple character controller and a simple patrolling AI over a specific path. However, these movements work in real time and I want to change that to turn based. The AI should wait for the player to finish his/her move and then move itself. The same goes for the player.
Both the player and AI should be able to move to their adjacent waypoints only when the movement of the other part is complete.
How should I go about that?
Thank you
The language that I'm writing in is UnityScript.

As a very simple solution, firstly you can create an empty gameobject. Name it as TurnController. With a simple script you can add a boolean variable on it. Lets name it as isPlayerTurn. For player movement you can check this, if it is true player can move. At the end of his/her move (maybe clicking end turn button or when it reachs the max distance to move or something else) you can set isPlayerTurn false. Ofcourse AI should check (Maybe in Update function. But can change by your design) if it is true, AI can do what it needs to do. And at the finish of its turn, it should change isPlayerTurn back to true. I know it is a very simple solution but hope it helps for begining. And I hope I didnt misunderstand your question.

Write the ai as a player instance and have it emulate player input.
(Instead you could also implement a common interface on both classes.)
Spawn a game object with a GameManager behaviour script that stores a reference to the current player (or ai). Then have the GameManager update the current player every frame by checking their input. If the (human) player gives input while it is not his turn, his input will just be ignored.
This way, the player and ai do not have to know if it is their turn.

Related

How do I use Is Valid check for completing my scoring system in UE4?

I'm having trouble finding the missing piece of the puzzle with my blueprint here. Under my turret blueprint, I'm trying to check if the turret is dead, if it is, then it executes the scoring system and adds some points. What I have here is not working though. Can someone help me find what I'm missing? Thanks.
Turret Blueprint
You've attached your code to the Event BeginPlay node which means your game will only check the turret and try to add points once, which will happen as soon as the game starts. We would need to know what causes your turret to "die" to give you a more accurate answer, E.g. is it hit by a projectile or a melee weapon, or does the player have to find their way to a switch to turn the turret off or blow it up etc.
You first need to identify the cause of the turrets death and trigger your score update from there. If for example your turret is destroyed by a projectile which the player shoots at it, you could check when another actor overlaps (I.e. hits) your turret and then check if the other actor is the player's projectile. If it is, you can then update the player's score and destroy the turret.
It is also usually best to store the player's score in the PlayerState instead of the GameMode. You would need to create your own PlayerState blueprint and configure your GameMode to use that blueprint. This can be done in the properties of the GameMode or in the project settings under Maps and Modes.
Below is a basic example of destroying a turret with a projectile and updating the player's score. But I would recommend searching YouTube for something like "ue4 damage enemy" or "ue4 dealing damage". There are loads of tutorials which will show you how to implement a damage system step by step.
Turret Blueprint
This blueprint uses the Event ActorBeginOverlap node to detect when another actor overlaps/hits the turret (both the turret and the other actor will need to have a collision box or sphere etc). Then it casts the other actor to BP_Projectile (a custom blueprint/actor which you would need to create). If the cast fails, the 'other actor' isn't a projectile so we don't want to destroy the turret. If the cast is successful, we can then get the player state from the player controller and call Update Score which is a custom event I've made in my PlayerState blueprint, passing the number of points killing the turret will give you. After updating the score we can destroy the projectile and then the turret itself.
Player State Blueprint
This blueprint just has a custom event which updates the PlayerScore variable.

Mouse cursor becomes locked during keyboard input

I'm attempting my first shot at using Unity. This is my first foray into game development and 3D environments. I'm following the tutorial for the survival shooter located here: https://unity3d.com/learn/tutorials/projects/survival-shooter/player-character?playlist=17144
I went to try mouse movement, which should change the direction of the player object, but found that the player does not change direction.
I have even tried copying the tutorial author's code directly, using it in its entirety and overwriting my original script. Their code can be found in the link.
Adding Debug.Log("Raycast not hitting"); to an else block in the Turning function causes the debug message to fire during each FixedUpdate, regardless of whether the mouse has been positioned over the floor.
Since you directly copied all scripts, I'm assuming that their are no issues with your scripts. This means that this issue is most likely located somewhere in your scene. The boolean controlling player, Physics.Raycast(camRay, out floorHit, camRayLength, floorMask). The else statement you used assures you that this function is returning false. I think the most likely reason this may be is that you do not have an object in the scene that has its layer set to floor. The aforementioned function will automatically return false if the RayCast does not find an object with a layer of floor within a range of camRayLengthunits. So, find or create an object that covers the entirety of the floor and set its layer to floor. I would also recommend looking at the scripting API documentation for Physics.Raycast so that you can better understand whats going on in the code. Here's a link to Unity's documentation: https://docs.unity3d.com/ScriptReference/Physics.Raycast.html

Path finding on a 2d plataformer game. Making enemies jump

I am working 2D Platform running game and I am stuck at this issue, i cant figure it out how to make my enemies jump through platforms as they follow the player. I used A* path finding with a Grid graph for my flying enemy and it works just fine. But with the ground troops i don't know what to do. Any recommendations where to start and what to study? Thanks in advance
Place a Trigger (Collider) attached with the Platform at the point where you want your enemy to Act (Jump in your case). and Attach a script to your Enemy to Handle its actions whenever it enters that trigger. you can make it Jump/Fly or whatever you want to. Thumb up if its helpful :)

unity3d player gameobject "hear" sounds

I have a question that is a little... complex
basically I want a gameObject (an enemy) "listen" to the sound of the player (footsteps, door opening, gunfire etc)
I could do this just fine by using:
>Collider[] hitColliders;
>hitColliders = Physics.OverlapSphere(transform.position, 10f,enemyLayer);
>
>for(int i=0;i<hitcolliders.Length;i++){}// Call Enemy Hear Player Function
However, the problem starts here:
I want the "sound" to be blocked by walls. At first, I thought I could use Physics.Linecast to do this. However, this means the sound could be blocked by a mere piece of pole, because Physics.Linecast only shoots a single, straight line.
What I want is player C could not hear anyone at all, but player A and B could still hear each other.
I hope you guys understand my question.
You could place the objects you want to block the soundwave on a specific layer. And just make the raycast ignore all other layers.
Leave all this Physic and other graphical stuff behind.
Create a separate logic for this behavior.
Create a big chess board (where x,y will be x,y position in you game) and add only sound-generators, sound-listeners and sound-obstacles.
Update this chess board each frame and create sounds, fly sounds, block sounds and listen to sounds and act appropriate as the real life actors.
This way you can add parameters to each obstacle, sound-generator and sound-listener so that all be configurable.

Unity help, indie horror game

I am making a game using a combination of Blender and Unity and have hit a wall. I am trying to make it so a lamp flies off of a table and smashes against a wall once the player walks past a certain point in the map.
I am having a hard time with this. Any help is appreciated.
You need to break this up into little parts.
The first part is that once the player walks past a certain point you want to do something. To do this, look at http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
An on trigger event will let you run some code when an object collides with another object. In your case, when your player collides with a certain point in the game.
Next, inside that OnTriggerEvent, you want to fire the lamp off the table. To best do this, create a keyframe animation (or whatever you're most comfortable with) that animates the lamp to fly off the table. Lastly, play that animation in the trigger event. http://unity3d.com/learn/tutorials/modules/beginner/animation
To summarize, when the user hits a certain point, play an animation on the lamp.