Jump to content
Sign in to follow this  
galzohar

Stop vehicle bouncing on vehicle respawns

Recommended Posts

I've seen this problem both with my script and on servers that have vehicle respawns with different script, so this seems to be a generic issue. We know that createVehicle doesn't create it in the exact location you ask for, and you need to setPos and setDir it to the exact location you want. However, when doing this the vehicle seems to "bounce" around a bit, which means it won't end up where it is supposed to be (and it looks pretty stupid).

This script will wait until vehicle gets damaged or gets used. If it gets damaged it'll respawn it (spawn protection), and if it gets used it'll wait until it's not used for 2 minutes straight (be it due to destruction or abandoning) and then respawn it.

#define MAX_SPAWN_DAMAGE 0.001
private ["_vehicle", "_delay", "_initSQF", "_startpos", "_startdir", "_type", "_startTime", "_damageEnabled"];
if (!isServer) exitWith{};

_vehicle = _this select 0;
_delay = _this select 1;
_initSQF = _this select 2;
_startpos = getpos _vehicle;
_startdir = getdir _vehicle;
_startTime = - _Delay;
_type = typeof _vehicle;
_damageEnabled=0;

if (_initSQF==_initSQF) then
{
[_vehicle] execVM _initSQF;
};

waitUntil {!(({alive _x} count (crew _vehicle)) == 0) || ((getDammage _vehicle)>MAX_SPAWN_DAMAGE)};


while {true} do
{
p1 GlobalChat "reacehd loop";
if (!(({alive _x} count (crew _vehicle)) == 0) || (_damageEnabled==1)) then {
	p1 GlobalChat "reached first if";
	_damageEnabled=1;
	waitUntil {(({alive _x} count (crew _vehicle)) == 0)};	
	p1 GlobalChat "time started";
	_startTime=time;
	waitUntil {(time > (_startTime + _delay)) || !(({alive _x} count (crew _vehicle)) == 0)};
	p1 GlobalChat "time ended";
};

if (_damageEnabled==1) then {p1 GlobalChat "between ifs, allow damage";} else {p1 GlobalChat "between ifs, not allow damage";};
if (time > (_startTime + _delay) || (_damageEnabled==0)) then
{
	p1 GlobalChat "reached respawn1";
	deletevehicle _vehicle;
	sleep 0.5;
	[b]_vehicle = _type createvehicle _startpos;
	_vehicle setpos _startpos;
	_vehicle setdir _startdir;[/b]
	_damageEnabled=0;
	if (_initSQF==_initSQF) then
	{
		[_vehicle] execVM _initSQF;
	};

	waitUntil {!(({alive _x} count (crew _vehicle)) == 0) || ((getDammage _vehicle)>MAX_SPAWN_DAMAGE)};
};
};

Note that MAX_SPAWN_DAMAGE is meant for spawn protection - if it's set to 1 spawn, protection would be disabled (though it's probably more efficient to use a different script if you don't want spawn protection).

The 3 lines in bold are probably the problem. Any better way to do this to avoid the bouncing?

Share this post


Link to post
Share on other sites

setVelocity [0,0,0]... ? Also, make sure when you setPos it the vehicle isn't partially submerged in the ground or colliding with other objects (might even help to setPos it a few inches or so above the ground).

Share this post


Link to post
Share on other sites

I really dont think this is possible to fix, since the "bouncing" is just the vehicle spawning a little higher than terrain and then becoming physically active (ie the suspension starts reacting).

You dont need to setpos it btw. You already created it in the same position.

Share this post


Link to post
Share on other sites
You dont need to setpos it btw. You already created it in the same position.

CreateVehicle often choses a position close to the given position, not always exactly at that position.

---------- Post added at 02:47 PM ---------- Previous post was at 02:45 PM ----------

since the "bouncing" is just the vehicle spawning a little higher than terrain and then becoming physically active (ie the suspension starts reacting).

That might cause it to bounce a little, but not enough to move it around a lot. I think his problem is that it's being created "inside" of something or partially underground.

Share this post


Link to post
Share on other sites

Well it is spawning exactly where it started (with this script, it saves starting position and direction and setPos and setDir it there on respawn), then again you can't really see if it bounces at map startup due to "receiving" black screen.

setVelocity seems to do nothing, so I'm assuming they spawn with 0 velocity already. It feels like more of an issue with the vehicle spawning with improper slope. Any way to also save the rest of the angels? I only know how to save heading around the Z axis (normal getDir/setDir) but can't get the other 2 DOF, saving the other 2 may stop the bouncing.

Another problem I get is that when a vehicle respawns it takes about 10 seconds before anyone can enter it, though it's probably a problem with the game that might not be fixable by scripting.

Share this post


Link to post
Share on other sites

Use getVectorUp, getVectorDir, and setVectorDirAndUp to get the rotation correct.

As for the delay before being able to get in, use reveal to reveal it to the player... as soon as the player has "detected" it he should be able to use it.

Share this post


Link to post
Share on other sites
CreateVehicle often choses a position close to the given position, not always exactly at that position.

Isnt that the point? Aside from abstract art, I really dont see the point of spawning a vehicle halfway inside a building :p

Regarding the vectors, I fail to see what they would do, unless you set like the exact same vector every millisecond for 2-3 seconds or something... In which case I still think it will bounce when you release it.

What would happen if you spawn it far away, wait 2-3 seconds, then move it to the proper position?

Share this post


Link to post
Share on other sites

No combination of these commands seems to work. Trying to spawn the vehicle at a completely remote location and THEN setting its position seems to help but it still bounces a bit, and then again when putting this together with everything else causes a complete mess (multiple respawns, opposite directions and other weird stuff).

Share this post


Link to post
Share on other sites

Doesn't work either. Setting it to spawn above ground by 0, 0.05, 0.1, 1, -0.1, -1 all caused bouncing.

Share this post


Link to post
Share on other sites

Thats the way to do it normally.

---------- Post added at 21:52 ---------- Previous post was at 21:51 ----------

Can you please make a short vid. Make we do have a different idea of the problem.

Share this post


Link to post
Share on other sites

it seems to be worse the heavier the vehicle, with bikes for example it's barely noticeable (but still there), and with abrams it can really throw them like nuts. I'll see if I can make a video small enough in size so that my internet can actually handle uploading it within a reasonable time.

2lygQ_tDkvg

You can see it's a MUCH bigger issue with heavier vehicles, and need to look carefully to see that it's also an issue with lighter vehicles.

Edited by galzohar

Share this post


Link to post
Share on other sites

I can't quite see what you're doing but it's possible the new vehicle is spawning on top of the old one before the old one is properly removed. what happens with a 2 second wait, for example?

Share this post


Link to post
Share on other sites
I can't quite see what you're doing but it's possible the new vehicle is spawning on top of the old one before the old one is properly removed. what happens with a 2 second wait, for example?

2 seconds don't help either.

This script seems to be no different from other respawn scripts used in other missions, either, and I definitely noticed this happening in them as well. I don't recall seeing smoothly respawning vehicles in any mission.

Share this post


Link to post
Share on other sites

I've noticed the same thing. In one of my missions I had to add few secs of sleep and then setpos the camo net, after the vehicle had stopped bouncing. Otherwise it would pull the net down. :/

Share this post


Link to post
Share on other sites

Tried one vehicle per camo netting? Two that close might just be too close.

Of course, you could solve it with a more extravagant approach... Have the tank spawn in a "factory" where players cant see it easily (one of the hangars or whatever), have AI crew it, drive it to the "spawn position", get out, erect a camo tent and then go back to the factory, lol.

I mean the engine supports it and there will be no more visible bouncing ;)

Share this post


Link to post
Share on other sites

galzohar, two things.

1. I want that gun. :)

2. Try driving the vehicle away from it's spawn point and destroying it. I have a feeling that it's because you're spawning them instantly at the same location they are that's causing some of the bouncing. It's rare that a vehicle will be destroyed and respawned that quickly in place and if it does happen bouncing vehicles are probably the least of your worries. :)

Share this post


Link to post
Share on other sites

1) Try without camo net.

2) For some reason your vehicles seem to fly. Instead they should drop the the ground,

if created slightly above ground.

So something seems fishy here. :)

Share this post


Link to post
Share on other sites

I'm not destroying the vehicles, it's a form of spawn protection - if a vehicle takes more than 0.001 damage before it even got used it will respawn instantly. Once someone enters the vehicle for the first time after it respawned, the spawn protection is disabled and a normal respawn timer is used. This is easier to implement than "allowDamage false" (which needs to be run on all clients).

Without the nets the bouncing is reduced, but they still bounce a bit. Though they aren't touching the nets - I can easily drive them out without doing any damage to the nets.

Share this post


Link to post
Share on other sites
I'm not destroying the vehicles, it's a form of spawn protection - if a vehicle takes more than 0.001 damage before it even got used it will respawn instantly. Once someone enters the vehicle for the first time after it respawned, the spawn protection is disabled and a normal respawn timer is used. This is easier to implement than "allowDamage false" (which needs to be run on all clients).

This is easier?? I'm sure there are plenty of easier ways lol.

For example:

this addEventHandler ["handleDamage",{if(<condition for not taking damage>)then{false}else{_this select 2}}]

Share this post


Link to post
Share on other sites

Can the condition include a local/private variable?

What is "this"? The vehicle?

Anyway, the bouncing happens on "normal" respawns as well.

Share this post


Link to post
Share on other sites
Can the condition include a local/private variable?

What is "this"? The vehicle?

Sure. The _this in this case (lol) is [(this)object, hitLocation, damage, shooter, roundType].

Share this post


Link to post
Share on other sites

Eventhandlers (with the exception of a few) are global, so yes. Also, vehicle damage doesn't exactly something that could be out of sync (otherwise extremely strange situations would occur), so the effects of anything that does damage would have to be global... one would think.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×