mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-04-24 15:27:12 -05:00
First Attempt at making the arrow apply contact to objects
This commit is contained in:
parent
047f18e472
commit
c6f1ecbbec
|
|
@ -14,6 +14,7 @@ GameObject:
|
|||
- component: {fileID: 26604539265034266}
|
||||
- component: {fileID: 2287528990630677962}
|
||||
- component: {fileID: 54086400264625859}
|
||||
- component: {fileID: -7840242488604773719}
|
||||
m_Layer: 0
|
||||
m_Name: Arrow
|
||||
m_TagString: Untagged
|
||||
|
|
@ -162,3 +163,17 @@ MonoBehaviour:
|
|||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
--- !u!64 &-7840242488604773719
|
||||
MeshCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 26604539265034264}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 1
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
m_Convex: 1
|
||||
m_CookingOptions: 30
|
||||
m_Mesh: {fileID: 8211372540250625004, guid: c93393c6eb5bb2b489536f1f078c73c0, type: 3}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using MLAPI;
|
||||
using MLAPI.Messaging;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class Arrow : NetworkBehaviour {
|
||||
|
|
@ -8,11 +9,29 @@ public class Arrow : NetworkBehaviour {
|
|||
|
||||
public float speed = 90f;
|
||||
|
||||
[SerializeField] private float bumpPower = 30;
|
||||
|
||||
//finds targed
|
||||
public void Seek(UnityEngine.Vector3 _target) {
|
||||
//can also do effects, speed on the bullet, damage amount, etc.
|
||||
target = _target;
|
||||
isLive = true;
|
||||
|
||||
// Start a co-routine to despawn the arrow if it doesn't hit anything
|
||||
StartCoroutine(DespawnCountdown());
|
||||
}
|
||||
|
||||
IEnumerator DespawnCountdown() {
|
||||
int time = 15;
|
||||
|
||||
for (int i = time; i > 0; i--) {
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
}
|
||||
|
||||
// Time's up - Despawn us | Only despawn once
|
||||
if (IsHost) {
|
||||
HitTargetServerRPC();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
@ -32,29 +51,41 @@ public class Arrow : NetworkBehaviour {
|
|||
// Calculate distance
|
||||
float distanceThisFrame = speed * Time.deltaTime;
|
||||
|
||||
|
||||
// Checking from current distance to current target
|
||||
if (dir.magnitude <= distanceThisFrame) {
|
||||
// NOT SURE IF THIS CALC ^ WORKS AS INTENDED
|
||||
HitTargetServerRPC();
|
||||
return;
|
||||
}
|
||||
|
||||
//move in the worldspace
|
||||
transform.Translate(dir.normalized * distanceThisFrame, Space.World);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Is called whenever something collides with the bumper
|
||||
void OnTriggerEnter(Collider objectHit) {
|
||||
if (objectHit.transform.parent.gameObject.tag == "Player") {
|
||||
//Checks if the other object is the player
|
||||
PlayerMovement playerMovement = objectHit.GetComponent<PlayerMovement>();
|
||||
|
||||
float DirBumpX = playerMovement.driftVel.x * -1;//Inverts the Player Velocity x
|
||||
float DirBumpY = .1f;
|
||||
float DirBumpZ = playerMovement.driftVel.z * -1;//Inverts the Player Velocity z
|
||||
|
||||
Vector3 DirBump = new Vector3(DirBumpX, DirBumpY, DirBumpZ);//Creates a direction to launch the player
|
||||
DirBump = Vector3.Normalize(DirBump);//Normalizes the vector to be used as a bump direction
|
||||
|
||||
playerMovement.GetHit(DirBump, bumpPower);
|
||||
//
|
||||
}
|
||||
|
||||
// If it hits anything else, we still want to despawn it
|
||||
|
||||
// Despawn the arrow
|
||||
HitTargetServerRPC();
|
||||
}
|
||||
|
||||
// Arrow has connected with something
|
||||
[ServerRpc]
|
||||
private void HitTargetServerRPC() {
|
||||
isLive = false;
|
||||
|
||||
// Do the hit logic
|
||||
|
||||
// Despawn the arrow
|
||||
this.gameObject.GetComponent<NetworkObject>().Despawn(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user