Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Bullet : MonoBehaviour
- {
- public int Speed;
- public float Angle;
- float t = Mathf.PI;
- Vector3 _StartPos;
- Vector3 LastPos;
- // Use this for initialization
- void Start ()
- {
- LastPos = transform.position;
- Angle = Vector3.Angle (Vector3.forward, transform.forward);
- Angle = Mathf.Deg2Rad * Angle;
- _StartPos = transform.position;
- }
- void Update()
- {
- t += Time.deltaTime;
- float vz = Speed*t* Mathf.Cos (Angle) * Time.deltaTime;
- float vy = Speed*t* Mathf.Sin (Angle)* Time.deltaTime-(9.8f*(t*t))/2* Time.deltaTime;
- Debug.Log (Mathf.Cos (Angle)*t);
- Vector3 NextPos = new Vector3 (transform.position.x, transform.position.y + vy, transform.position.z + vz);
- transform.position = NextPos;
- RaycastHit hit;
- if (Physics.Linecast(LastPos, transform.position, out hit))
- {
- print (hit.transform.name);
- Destroy (gameObject);
- }
- LastPos = transform.position;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement