- Home /
How to stop textures flickering
When I instantiate a bullet hole on a cube it starts flickering and this is something that I find unpleasant for my game, but when I instantiate a bullet hole on a rounded surface, like a capsule, it doesn't flicker. So how do I fix this? Here's what I mean: http://videobam.com/LcUNs
Here's my script:
var Barrel : RaycastHit;
var Cam : Camera;
var BulletHole : GameObject
function Update () {
hitRotation = Quaternion.LookRotation(Barrel.normal, transform.up);
}
function Shoot () {
if(Physics.Raycast(transform.position, Cam.transform.forward, Barrel, 60)){
yield WaitForSeconds(0.1);
var newBulletHole = Instantiate(BulletHole, Barrel.point, hitRotation);
newBulletHole.transform.up = Barrel.normal;
CurrentAmmo -= 1;
print("The ammo of the MTAR is " + CurrentAmmo);
newBulletHole.transform.parent = Barrel.transform;
if(Barrel.transform.tag == "Player"){
Barrel.rigidbody.AddForce(Cam.transform.forward * BulletImpactForce);
}
if(Barrel.transform.tag == "Detail"){
Barrel.rigidbody.AddForce(Cam.transform.forward * BulletImpactForce);
}
}
}
Answer by william9518 · Dec 23, 2013 at 06:11 PM
Make the bullet hole prefabs SLIGHTLY in front of the cube. The reason it is flickering is because it is actually half in and half out of the cube, and it does not flicker on a curved surface because if you think about it, the surface curves away from the prefab so it is not actually inside the sphere. Move it slightly in front of the cube, like 0.001 would be enough.
Well, how would I do that? Because no matter what I do, it returns an error like "Operator '-' cannot be used with a left hand side type of 'UnityEngine.Vector3' and a right hand side type of 'float'."
I'm basically trying "newBulletHole.transform.up -0.001;"
But I guess that's not possible.
Answer by Sarmad123 · Nov 01, 2017 at 12:17 PM
you can override your position just by writing this line to stop flicking Barrel.point = new Vector3 (Barrel.point.x - 0.001f,Barrel.point.y - 0.001f,Barrel.point.z - 0.001f);
Your answer
Follow this Question
Related Questions
Parenting Bullet Holes? 1 Answer
Adding bullet holes to walls 3 Answers
Checking material on raycast 1 Answer
ContactPoint with OnParticleCollision? 0 Answers