Jump to content
Sign in to follow this  
wok

Protecting area from vehicles with setVelocity

Recommended Posts

I've been thinking about an invisible barrier to protect a spawn area from ground vehicles, and I thought about using setVelocity. This is a simple test mission I made to show the idea http://www.sendspace.com/file/xfgc3p

I used setVelocity [0,20,0] on a trigger so when the vehicle hits it it bounce back, lower values than 20 seem to let the vehicle pass. The main issue is that that works only when driving from one side of the trigger, if you drive from the other side it doesn't work well. I never really understood speed vectors and much less using sin and cos to calculate their value, does someone has an idea on how I could make this invisible barrier worh the same on all sides of the rectangle trigger or even in a circle trigger?

I guess I would have to use something like http://community.bistudio.com/wiki/direction but im not sure how to apply it.

Edited by wok

Share this post


Link to post
Share on other sites

Search yields this:

http://forums.bistudio.com/showthread.php?150008-Boat-get-stuck&p=2338274&viewfull=1#post2338274

_dir = (direction _boat) - 180;
_boat setVelocity [sin (_dir) * 15, cos (_dir) * 15, 0];

Edit: So you need to replace _dir with the direction to the center of the trigger, and apparently there's a function called BIS_fnc_relativeDirTo that you can use. _dir = [_veh, centerobject] call BIS_fnc_relativeDirTo; So the full script based on yours would probably be like

private ["_veh","_vehType","_dir","_reversedir"];
_veh = _this select 0;
_vehType = typeOf _veh;

if (_veh isKindOf "ParachuteBase" || !alive _veh) exitWith {};

_dir = [_veh, centerobject] call BIS_fnc_relativeDirTo;
_reversedir = _dir - 180;
_veh setVelocity [sin (_reversedir) * 20, cos (_reversedir) * 20, 0];

Edited by Magirot

Share this post


Link to post
Share on other sites

This is because velocity is vector setting second param will add velocity going from south to north

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  

×