Sign in to follow this  

Vehicle shoots self

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, Has anyone had to deal with objects (vehicles) that launch projectiles which can hit the launching vehicle? I can see a few approaches: 1. Wait a short time period and then 'arm' the projectile. 2. Wait til projectile has travelled a bit then arm it. 3. Wait until the projectile is not colliding with anything then arm it. I want it so that its possible for some vehicles to be able to shoot themselves in certain situations, so can't exclude collisions with the launching vehicle totally. Anyone here dealt with this before, and how well did your approach work?

Share this post


Link to post
Share on other sites
4. Do not allow the projectile to collide with the launch vehicle if its velocity is away from the direction of the launch vehicle.

Share this post


Link to post
Share on other sites
5) do not allow collision between projectile and parent, where the parent is the launching vehicle.

My problem here is I keep thinking about a tank, which is shooting itself by aiming down. Technically, the projectile is aimed "away" from the tank...but it still hits it. In this situation, I would simply have the turret and the tank be different collision areas (turret is parent, so collision with body is okay!), but that is far too specific and not wide enough an answer to be implemented in all your vehicle needs.

What kind of launching vehicles are you using? 2d or 3d?

Share this post


Link to post
Share on other sites
You could also set a timer on when it can hit the shooter, you could check for collision outside a physical radius, you could create the projectile outside of the vehicles collision range, or you could code in those "special situations".. such as bouncing a wall arms the projectile to be able to damage the shooting vehicle. There are probably a lot more ways than those listed by the three posters so far.

Share this post


Link to post
Share on other sites
I previously used the approach that the vehicle cannot be hit by a projectile moving away from it.

This is straightforward and doesn't require any additional state to be kept. It's the way to go.

Mark

Share this post


Link to post
Share on other sites
Just shoot the missile from a short distance in front of the vehicle (so it does not collide on the fist step). The velocity of the projectile should be missile.speed+vehicle.speed (because "at rest" the missile already has the speed of the vehicle carrying it).

Normally you shouldn't have to add anything else to your code.

Since the missile will go faster than the vehicle, the only ways the vehicle will be harmed by the missile are:
- missile exploding too close,
- vehicle getting in the trajectory of the missile (if it's a homing missile, or if the missile slows down and the vehicle can catch it).

Share this post


Link to post
Share on other sites
Because if it shoots up at an angle, it could still be facing "away", but legitimatly hit the vehicle.

Why not use some physics, and add the vehicle's velocity to thwe projectile's. Realistic, and when the vehicle is moving, it can't easily hit the projectile. And if it does, it was probably intentional.

Share this post


Link to post
Share on other sites
if the projectile doesn't hit tanks with the same direction as itself: how are you going to fix chases? You can't chase someone if the projectile just goes trough the target. Plus players might just start "running away" when a projectile is coming, to avoid it, and then turn back.

Share this post


Link to post
Share on other sites
The thing I see is to take the tank out of the canadate list for objects that take damage.

yeah, it sucks to be playing an online game with slow weapons that do lots of dammage and have killer lag. Eg. outrunning your own missile, only to be blasted by it.

Share this post


Link to post
Share on other sites
Vehicles are 3d. The main need is when aircraft launch missiles and their damn wings can get in the way if e.g. rolling.
I have a big vehicle with a turret that can shoot its own extremities though.

> falcone: I think that's cases 1 & 2, but I want the projectiles to spawn 'in-place' exactly where they are stored under the wings.

> sneftel/markr: no hit if velocity is moving away.
hmm nice sneaky idea, but won't work for the turret self-hittage.

> visage: yes, I want as you describe: e.g. tanks to be able to shoot their extremities.
Hmm spose I'll have to look into prodding my collision stuff for special cases :-/

I'm using proper velocity physics (setting projectile velocity to vehicle velocity on launch).

Share this post


Link to post
Share on other sites
'Usually', collision detection system and physics systems have callback mechanisms, when two objects collide, or are about to collide (broad phase detection), which gives you control over what to do after the collison is detected.

In the callback, you should be able to simply return that you do not want a missile to collide with it's launcher (return 'false', or a 'Don't Process' or 'skip', 'stop' flag, anything you fancy). Since the missile has the launcher's ID, or pointer, or whatever, it should be straight forward.

Then when the missile explodes on the ground, you can re-enable the damage to the vehicle, if the gunner was stupid enough to shoot at his own feet.

that can also be used for multiple effects, like enable friendly-fire or not.

That's how I'd do it anyway.

Share this post


Link to post
Share on other sites
Oluseyi, that might look a little...ugly to say the least. I suppose it really depends why kind of collision detection you do.

Personally, for a plane, I would have 1 bounding box for the cockpit and body, and one bounding box for the wings.

How are the wings getting in the way in a roll? Shouldn't the missile be well out of the way by the time the wings come around? Try setting the initial speed of the missile to be greater. Or, set the position to be JUST infront of the wing. So when it is shot, it is already infront of the wing...and since it has an initial velocity of the plances velocity plus some, it should never hit the wings when the plane rolls.

Any more information you can give us?

Share this post


Link to post
Share on other sites
missiles and rockets have a timer, so they get activated after a short while, probably to avoid that kind of problems. Like grenades, kind of a safety.

Share this post


Link to post
Share on other sites
You could let the damage happen and then the idiot who's stupid enough to shoot himself would get what he deserves [lol]


In all seriousness...you could give it a player ID for the owner of the projectile. If that owner is the same as the owner for the tank, don't cause damage.

Share this post


Link to post
Share on other sites
If a plane is travelling forward and rolling clockwise as it releases a bomb on its right wing the bomb would release but immediately hit the right wing if the plane is rolling fast enough.

Also it would theoretically be possible to roll and hit a missile that is being launched forward. This depends on the roll speed, launch speed and the distance the missle is mounted from the wing. In the real world a missile would be mounted properly and launch fast enough for this ever to happen (hopefully!). I don't think it's common practice to do insane barrel rolls while launching missiles anyway?

Take note on what oliii said about activation timers.

Share this post


Link to post
Share on other sites
Yep I spose you get what you deserve doing barrel rolls whilst firing ;)

I really can't simply exclude collisions with the firer vehicle as I *do* want hits to register e.g. where the player can see and aim at the launching vehicle (e.g. from a turret).

My missiles have thrust, drag, mass, gravity etc; maybe I could give em a bit more thrust to get out of the way quicker ;)

Think I'll try a timer approach then... distance would probably be better but more costly.

Share this post


Link to post
Share on other sites
With aircraft, those missiles are launched at a certain speed relative to the plane. So even if you're moving at Mach 3, that missile will shoot off at Mach 2 and maintain that speed, which is Mach 2 relative to the craft and Mach 5 relative to a stationary observer.

Just wanted to mention that.

Share this post


Link to post
Share on other sites
Quote:
Original post by iosys
If a plane is travelling forward and rolling clockwise as it releases a bomb on its right wing the bomb would release but immediately hit the right wing if the plane is rolling fast enough.


Is it in Hot Shots where they have a plane being loaded with a fat bomb mounted on the roof? arf, can't remember.

Share this post


Link to post
Share on other sites
I think the realistic thing to do would just be to make missiles etc have proper activation conditions. If I'm correct about it, then for ex the missiles on a plane's wing only activate after they are dropped (which means probably a single physics tick after detatching) and they also only blow up when the nose hits something (so if you say fly upside down and release a missile, it'd sit on the wing and accelerate off w/o exploding)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by oliii
Is it in Hot Shots where they have a plane being loaded with a fat bomb mounted on the roof? arf, can't remember.


Hahaha I can only image...

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
I think the realistic thing to do would just be to make missiles etc have proper activation conditions. If I'm correct about it, then for ex the missiles on a plane's wing only activate after they are dropped (which means probably a single physics tick after detatching) and they also only blow up when the nose hits something (so if you say fly upside down and release a missile, it'd sit on the wing and accelerate off w/o exploding)


Erk! I'll simply add rigid body dynamics into my system then ;)

Share this post


Link to post
Share on other sites
In my game I had this problem but due to the turret being able to swivel where it aims at the ship, to resolve this I have decided to make a 64x32 1bit 'image' from the turrets perspective at model load (or stored in the model)
and use a simple multiple then check the pixils to see if its currently aiming at the ship its attached to, if so, it just refuses to fire.

Share this post


Link to post
Share on other sites

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this