2075 / Unity / 3D / Постріл
Створити і штовхнути
GameObject tmp = Instantiate(bullet, transform.position, transform.rotation);
tmp.GetComponent<Rigidbody>().AddForce(transform.forward * speed);
Destroy(tmp, 3.0f);
// Quaternion.Euler(0, 0, 0)
// Quaternion.identity
Розгорнути патрон в напрямку пострілу
public GameObject weapon;
-----
bullet.transform.LookAt(weapon.transform.position);
bullet.transform.Rotate(0f, 180f, 0f);
Перемістити патрон, зупинити і знову штовхнути
public GameObject patron;
public Transform startPos;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
patron.transform.position = startPos.position;
patron.GetComponent<Rigidbody>().velocity = Vector3.zero;
patron.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
patron.GetComponent<Rigidbody>().AddForce(transform.forward * 1000);
}
}
Сліди від куль
void OnCollisionEnter(Collision collision) {
Vector3 position = collision.contacts[0].point; // 1 точка дотику
Quaternion rotation = Quaternion.LookRotation(collision.contacts[0].normal);
Instantiate(mark, position, rotation);
}
Якщо mark - це Quard, то його покласти в Пустий об'єкт і трохи посунути
а локалька вісь Z дивиться вгору