Help to simulate RE7 door system

Started by
1 comment, last by GWDev 5 years, 5 months ago

hello everyone.

i would just say i'm sorry for my bad english, i'll do my best to be more clear as possible.

i'm doing some practice with Unity and C# and right know i'm trying to understand how to emulate the RE7 door system, where the player hands are going to push the door when is closest to it, i found a tutoria for UE4 on youtube but nothing for unity..

what i actually have is a raycast to detect when i'm in front of the door, i can just open it by call an animation on some button press but i want to emulate it, but i'm totally confused on how to do it

this is my code for now


	private void CheckTheHittingDoor()
	{
		var fdw = transform.forward;
		RaycastHit hit;
		
		if(Physics.Raycast(transform.position,fdw,out hit,raycastLenght))
		{
			for (int i = 0; i < _doors.Length; i++)
			{
				if(hit.collider.CompareTag(_doors[i]))
				{
					Debug.Log(_doors[i]);
				}
			}
		}
	}

then this is the video link from youtube to show you what i mean.

 

VIDEO

 

thank's you in advance

Advertisement

Hi Sylon87

Fair warning: I didn't watch the video tutorial and didn't really play the game. So this is all from the first few seconds of the  linked video. But maybe it get's you started.

First of all, you do not neet to raycast all the time from the player out. If you know all the doors in the room (and their position) and the player postion you could just check the distance to the doors and see if you have line of sight to them and if the distance is smaller than X.

If you have a lot of doors this could be further optimized. The player has to move at least the distance to the currently closest door before you need to check again.

But if you have a working system, keep it for now.

 

The doors have three states.

  • Closed: not much to do here. Allowed transition to partially opend
  • Partially opend: The door can move further towards closed state or open state. Do this by animating door with Unity (https://unity3d.com/de/learn/tutorials/s/animation)  or you could use physics to make it more realistic
  • Open: not much to do here. Allowed transitioin to partially opend (if needed at all).

 

Every door that isn't in state "Partially opend" doesn't need any animation playing or any physics calculated.

Every door that is in state "Partially opend" AND right next to the player (or one player) needs to "move with the player".

  • If the player moved towards the door, the door opens a bit more till it reaches the state "Open".
  • If the player moves away from the door, the door closes a bit more till it reaches the state "Closed".

 

This topic is closed to new replies.

Advertisement