Skip to content

Commit

Permalink
Basic Fps where enemies try to shoot you only to one direction, you m…
Browse files Browse the repository at this point in the history
…ust not fall of the ring
  • Loading branch information
Menion93 committed Mar 31, 2017
1 parent 35bea75 commit 58ced36
Show file tree
Hide file tree
Showing 37 changed files with 370 additions and 0 deletions.
18 changes: 18 additions & 0 deletions BasicFps/Assets/PlayerHitDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerHitDetector : MonoBehaviour {

void OnCollisionEnter(Collision coll)
{
Debug.Log(coll.gameObject.tag);

// An object Collision has also features like
// finding the contact points of the collision.
if(coll.gameObject.tag == "EnemyAmmo")
{
Debug.Log("I've been hitted!");
}
}
}
12 changes: 12 additions & 0 deletions BasicFps/Assets/PlayerHitDetector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions BasicFps/Assets/Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added BasicFps/Assets/Prefabs/ammo.prefab
Binary file not shown.
8 changes: 8 additions & 0 deletions BasicFps/Assets/Prefabs/ammo.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added BasicFps/Assets/Prefabs/enemy.prefab
Binary file not shown.
8 changes: 8 additions & 0 deletions BasicFps/Assets/Prefabs/enemy.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added BasicFps/Assets/Prefabs/player.prefab
Binary file not shown.
8 changes: 8 additions & 0 deletions BasicFps/Assets/Prefabs/player.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions BasicFps/Assets/Scene.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added BasicFps/Assets/Scene/mainScene.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions BasicFps/Assets/Scene/mainScene.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions BasicFps/Assets/Script.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions BasicFps/Assets/Script/EnemySimpleBot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemySimpleBot : MonoBehaviour {

public GameObject ammoPrefab;

public float ammo;
public float projectileForce;

public Transform player;
public float maxDistanceSight;

public float cooldownBetweenShots = 1;

bool playerSeen;
float lastTimeFired;

Transform m_transform;

void Start()
{
m_transform = GetComponent<Transform>();
}

// Update is called once per frame
void Update ()
{
if(Time.time - lastTimeFired > cooldownBetweenShots && (playerSeen || CheckPlayerSeen()))
{
Shoot();
}
}

bool CheckPlayerSeen()
{
RaycastHit hit = new RaycastHit();

Physics.Raycast(
m_transform.position,
player.position - m_transform.position,
out hit,
maxDistanceSight
);
playerSeen = hit.collider != null && hit.collider.tag == "Player";

if(playerSeen)
{
Debug.Log("I see you!");
}

return playerSeen;

}

void Shoot()
{
if (ammo < 1)
{
Debug.Log("Damn i'm out of ammo!");
return;
}

ammo--;

// Instantiate a projectile and fire it towards the player
GameObject ammoInstance = Instantiate(ammoPrefab, m_transform.position, Quaternion.identity);
Vector3 forceDirection = player.position - m_transform.position;
ammoInstance.GetComponent<Rigidbody>().AddForce(forceDirection * projectileForce);

lastTimeFired = Time.time;
}
}
12 changes: 12 additions & 0 deletions BasicFps/Assets/Script/EnemySimpleBot.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions BasicFps/Assets/Script/PlayerMovement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour {

public float velocity;
public float pitchVel;
public float yawVel;

// A value between 0-90, it wont permit a rotation about the local x axis superior of
// pitchToleranceDegree, and inferior of minus pitchToleranceDegree. Must always be positive.
public float pitchToleranceDegree;

public Transform m_camera;

Transform m_transform;

// Use this for initialization
void Start ()
{
pitchToleranceDegree = Mathf.Abs(pitchToleranceDegree);

if (pitchToleranceDegree > 90)
pitchToleranceDegree = 90;

m_transform = GetComponent<Transform>();
}

// Update is called once per frame
void Update ()
{
//Update position
{

Vector3 v_direction = Input.GetAxis("Vertical") * m_transform.forward;
Vector3 h_direction = Input.GetAxis("Horizontal") * m_transform.right;

Vector3 direction = Vector3.Normalize(v_direction + h_direction) * velocity * Time.deltaTime;

m_transform.Translate(direction, Space.World);
}

// Update rotation
{
float yaw = Input.GetAxis("Mouse X") * yawVel * Time.deltaTime;
float pitch = -Input.GetAxis("Mouse Y") * pitchVel * Time.deltaTime;

//Rotate the player on the y axis, but only the camera on the local x axis
m_transform.Rotate(0, yaw, 0);

float currentPitch = m_camera.localRotation.eulerAngles.x + pitch;

// if the camera points too up or too down, adjust it
if (
currentPitch > pitchToleranceDegree &&
currentPitch < (360-pitchToleranceDegree)
)
{

if (currentPitch - pitchToleranceDegree < (360 - pitchToleranceDegree) - currentPitch)
{
currentPitch = pitchToleranceDegree;
}
else
{
currentPitch = -pitchToleranceDegree;
}
}

m_camera.localRotation = Quaternion.Euler(
currentPitch,
m_camera.localRotation.eulerAngles.y,
m_camera.localRotation.eulerAngles.z
);
}

}
}
12 changes: 12 additions & 0 deletions BasicFps/Assets/Script/PlayerMovement.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions BasicFps/BasicFps.CSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6CCA5ED6-5014-B06B-A900-859C92CE3ADD}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>Assembly-CSharp</AssemblyName>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Unity Subset v3.5</TargetFrameworkProfile>
<CompilerResponseFile></CompilerResponseFile>
<UnityProjectType>Game:1</UnityProjectType>
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
<UnityVersion>5.5.2f1</UnityVersion>
<RootNamespace></RootNamespace>
<LangVersion Condition=" '$(VisualStudioVersion)' != '10.0' ">4</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\UnityVS_bin\Debug\</OutputPath>
<IntermediateOutputPath>Temp\UnityVS_obj\Debug\</IntermediateOutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_5_2;UNITY_5_5;UNITY_5;UNITY_ANALYTICS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VIDEO;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;ENABLE_VSTU</DefineConstants>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\UnityVS_bin\Release\</OutputPath>
<IntermediateOutputPath>Temp\UnityVS_obj\Release\</IntermediateOutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_5_2;UNITY_5_5;UNITY_5;UNITY_ANALYTICS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VIDEO;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;ENABLE_VSTU</DefineConstants>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.XML" />
<Reference Include="System.Core" />
<Reference Include="Boo.Lang" />
<Reference Include="UnityScript.Lang" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="UnityEngine">
<HintPath>Library\UnityAssemblies\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>Library\UnityAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking">
<HintPath>Library\UnityAssemblies\UnityEngine.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PlaymodeTestsRunner">
<HintPath>Library\UnityAssemblies\UnityEngine.PlaymodeTestsRunner.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Analytics">
<HintPath>Library\UnityAssemblies\UnityEngine.Analytics.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.HoloLens">
<HintPath>Library\UnityAssemblies\UnityEngine.HoloLens.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.VR">
<HintPath>Library\UnityAssemblies\UnityEngine.VR.dll</HintPath>
</Reference>
<Reference Include="UnityEditor">
<HintPath>Library\UnityAssemblies\UnityEditor.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\PlayerHitDetector.cs" />
<Compile Include="Assets\Script\EnemySimpleBot.cs" />
<Compile Include="Assets\Script\PlayerMovement.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets" />
</Project>
20 changes: 20 additions & 0 deletions BasicFps/BasicFps.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2015
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicFps.CSharp", "BasicFps.CSharp.csproj", "{6CCA5ED6-5014-B06B-A900-859C92CE3ADD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6CCA5ED6-5014-B06B-A900-859C92CE3ADD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CCA5ED6-5014-B06B-A900-859C92CE3ADD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CCA5ED6-5014-B06B-A900-859C92CE3ADD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CCA5ED6-5014-B06B-A900-859C92CE3ADD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added BasicFps/ProjectSettings/AudioManager.asset
Binary file not shown.
Binary file not shown.
Binary file added BasicFps/ProjectSettings/DynamicsManager.asset
Binary file not shown.
Binary file not shown.
Binary file added BasicFps/ProjectSettings/EditorSettings.asset
Binary file not shown.
Binary file added BasicFps/ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file added BasicFps/ProjectSettings/InputManager.asset
Binary file not shown.
Binary file added BasicFps/ProjectSettings/NavMeshAreas.asset
Binary file not shown.
Binary file added BasicFps/ProjectSettings/NetworkManager.asset
Binary file not shown.
Binary file added BasicFps/ProjectSettings/Physics2DSettings.asset
Binary file not shown.
Binary file added BasicFps/ProjectSettings/ProjectSettings.asset
Binary file not shown.
1 change: 1 addition & 0 deletions BasicFps/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
m_EditorVersion: 5.5.2f1
Binary file added BasicFps/ProjectSettings/QualitySettings.asset
Binary file not shown.
Binary file added BasicFps/ProjectSettings/TagManager.asset
Binary file not shown.
Binary file added BasicFps/ProjectSettings/TimeManager.asset
Binary file not shown.
Binary file not shown.
Binary file modified CharacterMovement/Library/CurrentLayout.dwlt
Binary file not shown.
Binary file modified CharacterMovement/Library/assetDatabase3
Binary file not shown.

0 comments on commit 58ced36

Please sign in to comment.