Skip to content

Commit

Permalink
Ajuste de direcionalidade do modelo do player
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasVinicius314 committed Sep 1, 2022
1 parent 618edc6 commit 7858841
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@
"temp/": true,
"Temp/": true
},
"editor.rulers": [80]
"editor.rulers": [80],
"editor.tabSize": 2,
"prettier.tabWidth": 2
}
4 changes: 2 additions & 2 deletions Assets/Prefabs/Enemy.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ NavMeshAgent:
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 2.59
m_Acceleration: 8
m_Speed: 1.55
m_Acceleration: 2.82
avoidancePriority: 50
m_AngularSpeed: 120
m_StoppingDistance: 0
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44057134, g: 0.48920023, b: 0.569343, a: 1}
m_IndirectSpecularColor: {r: 0.44057152, g: 0.4892007, b: 0.5693435, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -2488,7 +2488,7 @@ Mesh:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: pb_Mesh36606
m_Name: pb_Mesh28168
serializedVersion: 10
m_SubMeshes:
- serializedVersion: 2
Expand Down Expand Up @@ -2713,7 +2713,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6c7eefc8f6b5e68458f28981e3eb5196, type: 3}
m_Name:
m_EditorClassIdentifier:
enemyPrefab: {fileID: 0}
enemyPrefab: {fileID: 2422363816341469345, guid: 878f06b5ada303f47b84bdd84f0d4917, type: 3}
--- !u!1001 &1876611742
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/GameManagerScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ System.Collections.IEnumerator SpawnLoop(GameObject prefab)
{
while (true)
{
for (int i = 0; i < 5; i++)
for (int i = 0; i < 1; i++)
{
var vector2 = Random.insideUnitCircle * 5;

Expand Down
59 changes: 50 additions & 9 deletions Assets/Scripts/PlayerScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,37 @@ public class PlayerScript : MonoBehaviour
Vector2 currentMoveInput;
Vector2 processedMoveInput;
Vector2 lastMove;

Vector3 characterVelocity;
Animator? anima;
GameObject? model;

float lastMoveTimestamp;
int killCount;
bool attackLock;

System.Collections.IEnumerator SpawnLoop()
System.Collections.IEnumerator AttackRoutine()
{
anima?.SetBool("attack", true);
attackLock = true;

yield return new WaitForSeconds(0.4f);

HandleAttack();
attackLock = false;

anima?.SetBool("attack", false);
attackLock = false;
}

void HandleAttack()
{
Debug.DrawRay(transform.position, transform.position + new Vector3{x = currentMoveInput.x, z = currentMoveInput.y}, Color.red);
var colliders = Physics.OverlapSphere(transform.position + new Vector3{x = currentMoveInput.x, z = currentMoveInput.y}, 1.7f, 0b1000000);
var offset = characterVelocity.normalized;

var colliders = Physics.OverlapSphere(
transform.position + offset,
1f,
0b1000000
);

foreach (var collider in colliders)
{
var enemyDied = collider.transform.parent.gameObject
Expand Down Expand Up @@ -60,15 +70,32 @@ void HandleMovement(CharacterController controller)
controller.SimpleMove(Vector3.ClampMagnitude(move, 1f) * 4f);
}

void HandleModelAnimation(GameObject model)
{
model.transform.rotation =
Quaternion.Lerp(
model.transform.rotation,
Quaternion.Euler(
0f,
Mathf.Atan2(characterVelocity.x, characterVelocity.z) * Mathf.Rad2Deg,
0f
),
.1f
);
}

public void Fire(InputAction.CallbackContext context)
{
if(attackLock) {
if (attackLock)
{
return;
}

if (context.performed)
{
var value = context.ReadValue<float>();
StartCoroutine(SpawnLoop());

StartCoroutine(AttackRoutine());
}
}

Expand Down Expand Up @@ -104,14 +131,23 @@ public void MoveCheck()
{
currentMoveInput = Vector2.zero;
}
anima?.SetFloat("speed", (controller?.velocity.magnitude??0f)/1.2f);

var tempCharacterVelocity = controller?.velocity ?? Vector3.zero;

if (tempCharacterVelocity.magnitude > .1f)
{
characterVelocity = tempCharacterVelocity;
}

anima?.SetFloat("speed", (controller?.velocity.magnitude ?? 0f) / 1.2f);
}

void Awake()
{
controller = GetComponent<CharacterController>();
playerInput = GetComponent<PlayerInput>();
anima = transform.Find("DogPolyart").GetComponent<Animator>();
model = transform.Find("DogPolyart").gameObject;
anima = model.GetComponent<Animator>();
}

void OnGUI()
Expand All @@ -127,5 +163,10 @@ void Update()
{
HandleMovement(controller: controller);
}

if (model != null)
{
HandleModelAnimation(model);
}
}
}

0 comments on commit 7858841

Please sign in to comment.