Added Site Data
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.UI.Image;
|
||||
|
||||
public class PistolComponent : MonoBehaviour
|
||||
{
|
||||
@ -10,6 +11,7 @@ public class PistolComponent : MonoBehaviour
|
||||
private bool IsEnabled = false;
|
||||
|
||||
GameObject targetObject;
|
||||
|
||||
[SerializeField]
|
||||
GameObject targetObjectPrefab;
|
||||
[SerializeField]
|
||||
@ -21,6 +23,8 @@ public class PistolComponent : MonoBehaviour
|
||||
[SerializeField]
|
||||
private float maxProjectileDuration = 5f;
|
||||
|
||||
|
||||
|
||||
//private Dictionary<int,float> projectiles = new Dictionary<int, float>();
|
||||
|
||||
// Start is called before the first frame update
|
||||
@ -34,6 +38,21 @@ public class PistolComponent : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
private float CalculateDrop(Vector3 origin,Vector3 destination,Vector3 force)
|
||||
{
|
||||
// Calculate the initial velocity required to reach the destination.
|
||||
Vector3 displacement = destination - origin;
|
||||
float time = Mathf.Sqrt(2f * displacement.magnitude / Physics.gravity.magnitude);
|
||||
Vector3 velocity = (displacement - 0.5f * Physics.gravity * time * time) / time + force;
|
||||
|
||||
// Calculate the height the object will reach during its flight.
|
||||
float maxHeight = origin.y + velocity.y * time - 0.5f * Physics.gravity.y * time * time;
|
||||
|
||||
// Calculate the distance the object will drop during its flight.
|
||||
float dropDistance = maxHeight - destination.y;
|
||||
|
||||
return dropDistance;
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
@ -44,6 +63,9 @@ public class PistolComponent : MonoBehaviour
|
||||
if (Physics.Raycast(ray, out hit, 50))
|
||||
{
|
||||
targetObject.gameObject.transform.position = hit.point;
|
||||
float drop = CalculateDrop(this.bulletSpawnPoint.position, hit.point, this.transform.up * this.firePower);
|
||||
print(drop);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user