raf*_*asq 0 c# simulation unity-game-engine
下面的CSV为我x,z提供了id = 1在给定时间内t以秒为单位的汽车坐标.
我能够在每一秒更新汽车游戏对象的变换位置就好了.问题在于,当汽车的方向发生变化时,我需要能够旋转(或逼真地转动)汽车,使其指向正常的方向.我现在尝试使用简单的Lerp旋转(然后使用标准资产CarController脚本使之后更加逼真).
我现在面临的当前问题是知道汽车何时转弯,以及如何确定汽车的转向,以及转向哪种方向.我怎么能这样做?
t,id,x,z
908,1,0.00,755.17
909,1,-1.50,732.50
910,1,-1.50,715.84
911,1,-1.50,699.17
912,1,-1.50,682.50
913,1,-1.50,679.19
914,1,-1.50,679.19
915,1,-1.50,679.19
916,1,-1.50,653.52
917,1,-1.50,636.85
918,1,-1.50,620.19
919,1,-1.50,603.52
920,1,-1.50,586.85
921,1,-1.50,570.19
922,1,-1.50,553.52
923,1,-1.50,536.85
924,1,-1.50,521.94
925,1,-1.50,521.94
926,1,-1.50,521.94
927,1,-1.50,521.94
928,1,-1.50,521.94
929,1,-1.50,521.94
930,1,-1.50,521.94
931,1,-1.50,496.28
932,1,-1.50,479.61
933,1,-1.50,462.94
934,1,-1.50,446.28
935,1,-1.50,429.61
936,1,-1.50,412.94
937,1,-1.50,396.28
938,1,-1.50,379.61
939,1,-1.50,378.74
940,1,-1.50,378.74
941,1,-1.50,378.74
942,1,-1.50,378.74
943,1,-1.50,378.74
944,1,-1.50,378.74
945,1,-1.50,378.74
946,1,-1.50,350.07
947,1,-1.50,333.40
948,1,-1.50,316.74
949,1,-1.50,300.07
950,1,-1.50,283.40
951,1,-1.50,266.74
952,1,-1.50,250.07
953,1,-1.50,233.40
954,1,-1.50,232.39
955,1,-1.50,232.39
956,1,-1.50,232.39
957,1,-1.50,232.39
958,1,-1.50,232.39
959,1,-4.50,209.72
960,1,-4.50,193.05
961,1,-4.50,176.39
962,1,-4.50,159.72
963,1,-4.50,143.05
964,1,-4.50,126.39
965,1,-4.50,109.72
966,1,-4.50,93.05
967,1,-4.50,76.39
968,1,-4.50,59.72
969,1,-4.50,43.05
970,1,-4.50,26.39
971,1,-4.50,9.72
972,1,-4.50,6.00
973,1,-4.50,6.00
974,1,-4.50,6.00
975,1,-4.50,6.00
976,1,-4.50,6.00
977,1,-4.50,6.00
978,1,-4.50,6.00
979,1,-4.50,6.00
980,1,-4.50,6.00
981,1,-4.50,6.00
982,1,-4.50,6.00
983,1,-4.50,6.00
984,1,28.22,-4.50
985,1,49.25,-4.50
986,1,69.00,-4.50
987,1,87.67,-4.50
988,1,105.12,-4.50
989,1,121.45,-4.50
990,1,136.32,-4.50
991,1,149.74,-4.50
992,1,161.36,-4.50
993,1,171.13,-4.50
994,1,179.02,-4.50
995,1,185.12,-4.50
996,1,189.57,-4.50
997,1,192.60,-4.50
998,1,194.49,-4.50
999,1,195.56,-4.50
1000,1,196.11,-4.50
1001,1,196.37,-4.50
1002,1,196.48,-4.50
1003,1,196.54,-4.50
1004,1,196.54,-4.50
1005,1,196.60,-4.50
1006,1,196.60,-4.50
1007,1,197.25,-4.50
1008,1,198.58,-4.50
1009,1,200.53,-4.50
1010,1,200.53,-4.50
1011,1,201.35,-4.50
1012,1,201.45,-4.50
1013,1,202.27,-4.50
1014,1,202.27,-4.50
1015,1,202.60,-4.50
1016,1,202.60,-4.50
1017,1,202.60,-4.50
1018,1,202.60,-4.50
1019,1,202.60,-4.50
1020,1,202.60,-4.50
1021,1,202.60,-4.50
1022,1,202.60,-4.50
1023,1,202.60,-4.50
1024,1,202.60,-4.50
1025,1,202.60,-4.50
1026,1,202.60,-4.50
1027,1,202.60,-4.50
1028,1,202.60,-4.50
1029,1,202.60,-4.50
1030,1,202.60,-4.50
1031,1,202.60,-4.50
1032,1,202.60,-4.50
1033,1,202.60,-4.50
1034,1,202.60,-4.50
1035,1,203.32,-4.50
1036,1,204.85,-4.50
1037,1,206.85,-4.50
1038,1,206.98,-4.50
1039,1,207.90,-4.50
1040,1,207.90,-4.50
1041,1,208.48,-4.50
1042,1,208.48,-4.50
1043,1,208.48,-4.50
1044,1,208.48,-4.50
1045,1,208.48,-4.50
1046,1,208.48,-4.50
1047,1,208.48,-4.50
1048,1,208.48,-4.50
1049,1,208.48,-4.50
1050,1,208.48,-4.50
1051,1,208.48,-4.50
1052,1,208.48,-4.50
1053,1,208.48,-4.50
1054,1,208.48,-4.50
1055,1,209.48,-4.50
1056,1,211.48,-4.50
1057,1,214.45,-4.50
1058,1,214.45,-4.50
1059,1,214.45,-4.50
1060,1,214.45,-4.50
1061,1,214.45,-4.50
1062,1,214.45,-4.50
1063,1,214.45,-4.50
1064,1,214.45,-4.50
1065,1,214.45,-4.50
1066,1,242.67,-1.50
1067,1,264.63,-1.50
1068,1,286.36,-1.50
1069,1,307.90,-1.50
1070,1,329.29,-1.50
1071,1,350.45,-1.50
1072,1,371.40,-1.50
1073,1,392.12,-1.50
1074,1,412.58,-1.50
1075,1,432.75,-1.50
1076,1,452.60,-1.50
1077,1,472.06,-1.50
1078,1,491.06,-1.50
1079,1,509.51,-1.50
1080,1,527.29,-1.50
1081,1,544.25,-1.50
1082,1,560.23,-1.50
1083,1,575.01,-1.50
1084,1,588.37,-1.50
1085,1,600.11,-1.50
1086,1,610.06,-1.50
1087,1,618.16,-1.50
1088,1,624.44,-1.50
1089,1,629.05,-1.50
1090,1,632.22,-1.50
1091,1,634.21,-1.50
1092,1,635.36,-1.50
1093,1,635.95,-1.50
1094,1,636.23,-1.50
1095,1,636.35,-1.50
1096,1,636.42,-1.50
1097,1,636.42,-1.50
1098,1,636.48,-1.50
1099,1,636.48,-1.50
1100,1,636.48,-1.50
1101,1,637.48,-1.50
1102,1,639.48,-1.50
1103,1,642.45,-1.50
Run Code Online (Sandbox Code Playgroud)
请注意,这里有一个后续问题:Unity:在给定目标点和方向的情况下实际转向汽车
问题是,据我了解:
这很容易计算,但首先需要谨慎.对于车辆指向其当前正在移动的方向而言,并不总是看起来真实,特别是如果车辆正在转弯.汽车在急转弯时会滑行并漂移.飞机和火箭通过将自己指向不移动的方向并产生推力来精确操纵.帆船无法指向它们正在移动的方向,除非它们顺风移动.等等.您可能会发现需要一种更细致入微的方法,但在跑步前走路.
但确定速度矢量很简单. 速度是位置的第一次导数,你有位置和时间.
最简单的做法是取"当前"位置和"下一个"位置,减去它们,然后除以时差:
t, id, x, z
908, 1, 0.00, 755.17
909, 1, -1.50, 732.50
Run Code Online (Sandbox Code Playgroud)
从第二个减去第一个来获得增量:
t, id, ?t, ?x, ?z
908, 1, 1, -1.50, -22.67
Run Code Online (Sandbox Code Playgroud)
速度是距离除以时间,因此速度矢量v average是(Δx/Δt,Δz/Δt),所以这是你应该指向汽车的方向.
练习:你能计算每个点的加速度矢量吗?加速度是位置相对于时间的二阶导数.第三个是"混蛋",因为我们认为加速度的突然变化是一种"生涩"的运动; 你能计算出来吗?
练习:假设你有一个初始位置和一个时间序列的速度 ; 你可以走另一条路,从速度中产生位置吗?
练习:假设您的对象具有特定质量,并且您将获得初始位置,初始速度和力矢量的时间序列.你能算出速度和位置吗?(提示:牛顿告诉我们力,质量和加速度之间的关系?)
练习:太空中的火箭指向它们加速的方向,而不是它们移动的方向.但是太空中的火箭是无摩擦的,而汽车只能起作用,因为道路上存在摩擦力,因此汽车往往指向它们正在移动的方向.失去牵引力的汽车不必指向它正在移动的方向.你能想出一个确定汽车失去牵引力的模型吗?
| 归档时间: |
|
| 查看次数: |
190 次 |
| 最近记录: |