Hi guys, I have a problem. I used Etseekis tutorial on youtube for trajectory on a bullet and impact on the wall. It all works except my decals dont rotate to the object or wall they hit. They just stay flat, if that makes sense.
They hit a vertical surface, but show up as if they are on a horizontal surface.
var speed : float = 500;
var randomAngle : float = 0;
var lifeTime : float = 5;
var bulletGravity : float = 9.8;
var decalHitWall : GameObject;
var floatInFrontOfWall : float = 0.00001;
var force : float = 1.0;
@HideInInspector
var moveDirection : Vector3;
@HideInInspector
var shortestSoFar : float;
@HideInInspector
var instantiatePoint : Vector3;
@HideInInspector
var instantiateRotation : Quaternion;
@HideInInspector
var foundHit : boolean = false;
@HideInInspector
var parentToAdd : Transform;
private var triggerTime : float = 0.05;
function Awake ()
{
transform.Rotate((Random.value * 2 * randomAngle) - randomAngle, 0, Random.value *360);
moveDirection = transform.forward * speed;
shortestSoFar = Mathf.Infinity;
foundHit = false;
}
function Update ()
{
transform.rotation = Quaternion.LookRotation(moveDirection);
var hits : RaycastHit[];
hits = Physics.RaycastAll(transform.position, transform.forward, speed * Time.deltaTime);
for (var hit in hits)
{
if (hit.transform.tag == "Untagged")
{
if (Vector3.Distance(transform.position, hit.point) < shortestSoFar){
instantiatePoint = hit.point + (hit.normal * (floatInFrontOfWall + Random.Range (0,0.01)));
instantiateRotation = Quaternion.LookRotation(hit.normal);
parentToAdd = hit.transform;
shortestSoFar = Vector3.Distance(transform.position, hit.point);
foundHit = true;}
}
}
if (foundHit){
var spawnedBulletHole = GameObject.Instantiate(decalHitWall, instantiatePoint, instantiateRotation);
if (parentToAdd)
spawnedBulletHole.transform.parent = parentToAdd;
Destroy (gameObject);}
transform.position += moveDirection * Time.deltaTime;
moveDirection.y -= bulletGravity * Time.deltaTime;
lifeTime -= Time.deltaTime;
if (lifeTime < 0)
Destroy(gameObject);
}
If anyone can help with this, i would be most grateful. I am stoked this is working as good as it is though. Etseekis tutorial was great.