|
楼主 |
发表于 2014-6-26 16:18:01
|
显示全部楼层
本帖最后由 FFUR2007SLX2_5 于 2014-8-13 22:16 编辑
255楼,《武装突袭3——疯狂的戴夫和他的重量》
在我们“疯狂的道夫”开始旋转之前,他又给我们带来了几个新朋友:
https://community.bistudio.com/wiki/setMass
https://community.bistudio.com/wiki/getMass
https://community.bistudio.com/wiki/getCenterOfMass
https://community.bistudio.com/wiki/setCenterOfMass
当我们还在各种吐槽RV4的Physix时,波米则落落大方毫不掩饰的敞开衣襟让我们看了个遍。用过O2的朋友都知道我们的第一个盒子肯定不乏Mass这个词眼。她其实就是负责我们盒子在引擎中的重量,一个盒子250KG重,同时四个角也有各自的重量:
A3的“科尼赛格”只有1090KG!好轻啊,难怪可以跑出那么快的速度。(Agrea one-one也要1340kg耶)不过从现在开始我们可以用setMass和setCenterOfMass让我们的神级超跑更加逆天。setMass支持在时间的控制下逐渐控制重量,那么请试想在你逐渐轰油门的那一瞬间破天荒的减小车重将会是何等光景?“小黄车”可以拥有更快的加速度直到彻底失重四轮离地漂浮于空中,简直就是飞车中的极品。
接下来有请我们的Top Gear的Jeremy前来试车:
- /*
- Mass test, author: ffur2007slx2_5
- 0 = [vehicle player] spawn fn_MassTest;
- */
- private ["_car","_topSpeed","_code","_OldMass"];
- _car = [_this,0,objnull,[objnull]] call bis_fnc_param;
- if (_car iskindof "Car") then {
- if (canmove _car) then {
- _topSpeed = (configfile >> "CfgVehicles" >> typeof _car >> "maxSpeed") call bis_fnc_getcfgdata;
- _OldMass = getmass _car;
- _code = {
- private ["_car","_topSpeed","_ratio","_Oldmass","_NewMass"];
- _car = _this select 0;
- _topSpeed = _this select 1;
- _Oldmass = _this select 2;
- _ratio = (speed _car) / _topSpeed;
- _NewMass = _OldMass - (_OldMass * _ratio);
- _car setmass _NewMass;
- };
- ["ffur_00","OnEachFrame",_code,[_car,_topSpeed,_OldMass]] call bis_fnc_addStackedEventHandler;
- };
- };
复制代码
在使用该脚本前请即好安全带(我无法保证开快了你会不会飞出去),当然如果大家喜欢我们也可以用setMass来建立一个无重力的世界。getCenterOfMass可以让你看到重量集中在哪一个点上,setCenterOfMass则可以自由规划物体的重量集中在哪里。举个例子,波米的下一个Heli DLC吊装负重的模拟得用上setCenterofMass,直升机不同部位挂载的重物模拟就全靠上她们啦。等不及的朋友可以自己先开始体验一番啦!
接着上次的教程,体验了重力后疯狂的戴夫该出场了,今天他的任务是将翻斗车转出翔来。他将使用mass, setpitchbankyaw和attachto来克服setvelocity无法兼顾同时360度三轴旋转物体的软肋,将我们翻个底朝天。(FFUR_fnc_rotate测试版,暂时提供的方案仅供教程参考,函数FFUR_fnc_setPitchBankYaw位于https://community.bistudio.com/wiki/setVectorDirAndUp)
- /*
- FFUR_fnc_rotate
- author: ffur2007slx2_5
- description: Overcome the limitation brought by setvectordirandup and setvelocity, simulate physix simulation with on-the-fly rotation
- example: [power(scalar),angle(scalar),obj(obj),id(string)] spawn FFUR_fnc_rotate
- */
- private ["_power","_angle","_mass","_veh","_vector","_velocity","_distance","_a","_b","_duration","_temp_logic","_code","_halfDuration","_expotent","_random","_signed","_idString"];
- _power = [_this,0,0,[0]] call bis_fnc_param;
- _power = abs _power;
- _angle = [_this,1,0,[0]] call bis_fnc_param;
- _veh = [_this,2,objnull,[objnull]] call bis_fnc_param;
- if (_veh iskindof "man") exitwith {
- private "_msg";
- _msg = format ["%1 is kind of man, %2 instead.",_veh,typename objnull];
- [_msg] call BIS_fnc_error;
- };
- _idString = [_this,3,"",[""]] call bis_fnc_param;
- _mass = getmass _veh;
- _expotent = ((log _mass) / 2);
- _vector = [];
- _random = [0,1,2] call bis_fnc_selectrandom;
- _signed = [-1,1] call bis_fnc_selectrandom;
- {
- _veh setVariable [format ["FFUR_temp_var_%1",_x],0];
- } foreach ["a","b","c"];
- _veh setVariable ["FFUR_temp_down",false];
- for "_i" from 0 to 2 do {
- _vector set [_i,_power];
- };
- _velocity = [_vector,_angle] call BIS_fnc_rotateVector2D;
- _veh setvariable ["FFUR_temp_vector",_velocity];
- if ((!isnull _veh) && isServer) then {
- _a = _velocity select 0;
- _b = _velocity select 1;
- _distance = (sqrt ((_a ^ 2) + (_b ^ 2)));
- _duration = (_distance / 6);
- _halfDuration = (_duration / 2);
- _temp_logic = "logic" createvehiclelocal (position _veh);
- _code = {
- private ["_veh","_a","_b","_c","_logic","_halfDuration","_expotent","_duration","_EachRoundFrame","_random","_signed"];
- _veh = _this select 0;
- _a = _this select 1;
- _b = _this select 2;
- _c = _this select 3;
- _logic = _this select 4;
- _halfDuration = _this select 5;
- _expotent = _this select 6;
- _random = _this select 7;
- _signed = _this select 8;
- _EachRoundFrame = (360 * _expotent) / diag_fpsmin;
- private ["_constant_a","_constant_b","_constant_c"];
- _constant_a = (((_a / 2) / diag_fpsmin) / _halfDuration);
- _constant_b = (((_b / 2) / diag_fpsmin) / _halfDuration);
- _constant_c = ((_c / diag_fpsmin) / _halfDuration);
- _veh setvariable ["FFUR_temp_var_a",((_veh getvariable "FFUR_temp_var_a") + _constant_a)];
- _veh setvariable ["FFUR_temp_var_b",((_veh getvariable "FFUR_temp_var_b") + _constant_b)];
- _veh setvariable ["FFUR_temp_var_c",
- call {
- if (_veh getvariable "FFUR_temp_down") then [
- {(_veh getvariable "FFUR_temp_var_c") - _constant_c},
- {(_veh getvariable "FFUR_temp_var_c") + _constant_c}];
- }
- ];
- if (_a >= 0) then [
- {
- if (_b >=0) then [
- {
- _veh attachto [_logic,[
- (_veh getvariable "FFUR_temp_var_a"),
- (_veh getvariable "FFUR_temp_var_b"),
- (_veh getvariable "FFUR_temp_var_c")]];
- },
- {
- _veh attachto [_logic,[
- (_veh getvariable "FFUR_temp_var_a"),
- - (_veh getvariable "FFUR_temp_var_b"),
- (_veh getvariable "FFUR_temp_var_c")]];
- }
- ];
- },
- {
- if (_b >= 0) then [
- {
- _veh attachto [_logic,[
- - (_veh getvariable "FFUR_temp_var_a"),
- (_veh getvariable "FFUR_temp_var_b"),
- (_veh getvariable "FFUR_temp_var_c")]];
- },
- {
- _veh attachto [_logic,[
- - (_veh getvariable "FFUR_temp_var_a"),
- - (_veh getvariable "FFUR_temp_var_b"),
- (_veh getvariable "FFUR_temp_var_c")]];
- }
- ];
- }
- ];
- _veh setvariable ["FFUR_temp_vector",
- [_random,_signed,_EachRoundFrame] call {
- private ["_arr","_random","_signed","_EachRoundFrame"];
- _random = _this select 0;
- _signed = _this select 1;
- _EachRoundFrame = _this select 2;
- _arr = (_veh getvariable "FFUR_temp_vector");
- _arr set [_random,(_arr select _random) + (_signed * _EachRoundFrame)];
- _arr
- }
- ];
- [_veh,(_veh getvariable "FFUR_temp_vector")] call FFUR_fnc_setPitchBankYaw;
- };
- [_idString,"OnEachFrame",_code,[_veh,_a,_b,_power,_temp_logic,_halfDuration,_expotent,_random,_signed]] call bis_fnc_addstackedeventhandler;
- sleep _halfDuration;
- _veh setvariable ["FFUR_temp_down",true];
- sleep _halfDuration;
- [_idString,"OnEachFrame"] call bis_fnc_removestackedeventhandler;
- detach _veh;
- deletevehicle _temp_logic;
- };
复制代码
关于脚本中用到的bis_fnc_rotateVector2D我得画张图来解释这个函数:
我们将角a旋转一定角度后到黄色的角a,就这么简单。(如果说有一些新玩意比如log,wiki中我也做了相应的解释,理解应该不成问题)
好了,接下来就来看一下戴夫是如何将我们转出翔来的。
往我们的MP一扔,我们可以随时随地的将世界转个天翻地覆。比如说这样:
- {[random 360,random 360,_x select 0,_x select 1] spawn vbs3_fnc_rotate;} foreach [[car,"id0"],[car1,"id1"]…[car100,"id100"]];
复制代码
明天27日变形金刚4首映,想象一下在“爆点”中心放一个“机甲”什么玩意,一个大招100多辆车旋转着飞起,疯狂的戴夫应该会比较高兴。
作为本篇的结语,或许我们还能往船上不停的堆箱子把船堆沉了,把车子堆斜了,等等:)
(P.S. 当然对https://community.bistudio.com/w ... StackedEventHandler 感到非常抱歉,因为我至少还没有办法将所有的代码叠加到一个PFH中来最大化FPS)
#260 ArmA3 15 Years' Anniversary to continue the tutorial |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入VME
x
|