j'ai un soucis de spawn de bullet .
Le bulletSpawn est au bout de l'arme mais la balle spawn au pieds, je ne trouve pas la solution.
J'ai tenté plusieurs solution de rotation, de distance etc mais rien a faire, elle spawn toujours au pieds.
pas de soucis de collisions le player.
Merci de votre aide
voici le code
Code : Tout sélectionner
public GameObject bullet;
public Transform BulletSpawn;
void ShootRay ()
{
RaycastHit hit;
GameObject go = Instantiate (bullet, transform.position, Quaternion.identity) as GameObject;
Vector3 startPos = BulletSpawn.TransformPoint(Vector3.zero);
Vector3 endPos = Vector3.zero;
int mask = ~(1 << 9);
Vector3 directionToAttack = EnemyToAttack.transform.position - transform.position;
if(Physics.Raycast (startPos, directionToAttack, out hit, Mathf.Infinity, mask))
{
float distance = Vector3.Distance (BulletSpawn.transform.position, hit.point);
RaycastHit[] hits = Physics.RaycastAll(startPos, hit.point - startPos, distance);
foreach(RaycastHit hit2 in hits)
{
if(hit2.transform.GetComponent<Rigidbody>())
{
Vector3 direction = hit2.transform.position - transform.position;
direction = direction.normalized;
hit2.transform.GetComponent<Rigidbody>().AddForce(direction * 200);
}
/*else if(hit2.transform.GetChild<Destructible>())
{
hit2.transform.GetComponent<Destructible>(). destruct = true;
}*/
}
endPos = hit.point;
}
}