|
Hey guys, Fairly new to unity, and scripting in general. Working on my first project and having one issue i cant find and answer for. Im making a top down shooter, i have most of the basic mechanics set up, the issue im having is that the projectiles the player shoots, while colliding correctly closer to the player, stop being detected if the enemy is at a distance from the player. The distance is around 7 units, and only while the target is moving (collision appears to work normal when i make them stand still). I am also using the dontgothroughthings.js on the projectile. The code is pretty rough
(comments are locked)
|
|
Ok how about "Collision Detection" to "Continuous" or "Continuous Dynamic" on the bullet? If that doesn't do it, syclamoth's suggestion of raycasts might be your best bet:
Example: Continuous Dynamic just created a whole other lot of issues (enemies would just stop in place after being hit??) trying this raycast thing, got "BCE0023: No appropriate version of 'UnityEngine.Physics.Raycast' for the argument list '(UnityEngine.Vector3, UnityEngine.Vector3, float, UnityEngine.RaycastHit)' was found." trying to work through it myself obviously but thought id put it up here too.
Dec 08 '11 at 06:17 AM
Piat
Whoops, I wrote that in a rush and it was untested. I just corrected it in the post above; try again. Also, note that the bullet now no longer requires a collider, and neither the bullet nor enemy require a rigidbody. The enemy now just needs a collider and the "Enemy" tag.
Dec 09 '11 at 09:00 PM
blitzen
that seems to work a treat, thanks for all the help. I also found my own solution still using rigidbody collision, changing the projectile script to an addforce rather then a transform movement seemed to remove the issue.
Dec 09 '11 at 11:41 PM
Piat
(comments are locked)
|

I don't suppose that the distance after which the enemy isn't being collision-detected is, say, 20 speed * 4 seconds = 80 units' distance? :)
If not, this code looks fine, so try to narrow it down by setting up your test enemy at various distances and determine exactly how far away it is when it loses collision detection, pause the editor at that point and examine both the projectile and enemy in the inspector in debug mode.
If the answer doesn't become clear, post the information here along with any other scripts that might be running on any relevant game objects.
lol that was the very first thing i checked, but alas no, when the collision isnt being detected its quite clear that the projectile is passing through the target and carries on past it.
I will try and get exact numbers for the distances, and post more info.
question updated
Basically, rigidbody collisions are unreliable at high speeds and for small objects. See 'bullet through paper'. Try using raycasts between the bullet's positions every frame instead.
thanks for the tip, any direction you can point me for an example or tutorial in doing this, raycasting is probably the thing in understand least at this point