- Home /
Bullet moves fast and makes a late collision..
For some reason, the bullets which I instantiate are detecting collision lately... So it shows for example the particle and decal which are meant to be spawned when it collided at first place abit further...
lastBullet =(GameObject) Instantiate(Resources.Load ("bullet"),equippedWeapon.GetComponent<I_weapon>().gunPoint.position,equippedWeapon.GetComponent<I_weapon>().gunPoint.rotation);
lastBullet.rigidbody.AddForce(-equippedWeapon.GetComponent<I_weapon>().gunPoint.transform.forward*Time.deltaTime*5000,ForceMode.Impulse);
Its force speed is Time.deltaTime*5000... I think that is the problem but I still cant be sure..
The bullet object is a rigid body and it uses a square collider.
The collision detection part: (The code is one of the bullets components)
void OnTriggerEnter(Collider victim)
{
//Hitting a concrete wall.
else if(victim.gameObject.tag=="concrete" && owner!=victim.gameObject.GetPhotonView())
{
RaycastHit hit;
if (Physics.Raycast (transform.position, transform.forward, out hit, 100.0f)) //Will pick the walls rotation and will draw a decal from it.
{
Instantiate( Resources.Load("decal_concrete"),hit.point,Quaternion.LookRotation(hit.normal));
}
Instantiate(Resources.Load("particle_concrete"),transform.position+transform.TransformDirection(0,0,10) , Quaternion.Inverse(transform.rotation));
}
Destroy(this.gameObject);
}
Please help me, how do I get the bullet to detect the wall at the moment it gets into it?
$$anonymous$$ake sure if you have a fast moving rigidbody, that the COLLISION DETECTION is set to CONTINUOUS DYNA$$anonymous$$IC. Any other rigidbodies that this bullet will collide with need to be set to CONTINUOUS. That should solve your problem. Another thing that could help on top of that, is making the COLLIDER component a bit bigger. One other way that could help even more, to get more realistic physics, turn down the TI$$anonymous$$ESTEP, only a bit at a time until you are happy with the results. Hope this helps.
It does, with the time stamp,I already added the rest. And I dont wanna use the raycast for different reasons
Answer by AntiLunchBox · Jun 14, 2013 at 01:10 PM
If the bullet is moving that fast, you might as well just forget using a collision with it. Just use a raycast from the gun to where it's pointing and do your code from there. It is more reliable than using collision on really fast objects.
You could also try using this script on Unity Community if you still want to use this method: DontGoThroughThings
Answer by lighting · Jun 14, 2013 at 02:26 PM
I'm doing similar thing but with flying arrow. What helped me to catch collision on time is increasing time resolution in Time Manager (Fixed Timestep). It affects collision detection as it's for physics.
Answer by benk0913 · Jun 16, 2013 at 04:39 PM
Well, I actually tried raycasting, it works much better than the bullet instantiating and solves alot of problems. I recommend the raycast method for bullet shooting.
Your answer
Follow this Question
Related Questions
RigidBody stuck on wall when jumped against 7 Answers
Smart camera? 1 Answer
A Bullet's rigidbody, hit.normal 4 Answers
Rigidbody of empty bullet shell collision problem. 2 Answers