AutoCAD 3DMAX C語言 Pro/E UG JAVA編程 PHP編程 Maya動畫 Matlab應用 Android
Photoshop Word Excel flash VB編程 VC編程 Coreldraw SolidWorks A Designer Unity3D
 首頁 > Unity3D

Unity檢測發射體VS.防護碰撞

51自學網 2014-05-24 http://www.0532cf.com

本文選自StackOverflow(簡稱:SOF)精選問答匯總系列文章之一,本系列文章將為讀者分享國外最優質的精彩問與答,供讀者學習和了解國外最新技術,本文Unity碰撞檢測問題。

問題:

Tomáš Zato

我在嘗試檢測,發射體是否要撞擊防護體,以及碰撞在哪里發生。

這幅圖可以顯示出具體的情形,雖然A和B發射體距離中心防護體中心S的距離基本相同,但是一個會撞擊到防護體,另一個卻不會。

用簡單的數學來解決它,需要用到圓的數學方程和發射體路徑線的方程。只要用一支筆和一張紙,我就能計算出來。然而,我直接解析幾何的經歷非常糟糕。此外,發射體將離開防護體,返回陽極。怎樣過濾它們呢?

第二種方法是比較友好的方法——測量發射體路徑與防護體中心的最短距離,如果L比R小,就發生碰撞。看上去很容易實現,但是這不能讓我知道碰撞在哪里發生。

我做的是二維游戲,使用C#和Unity游戲引擎,歡迎大家提出各種通用解決方法。

發射體的大小忽略不計。

回答:

Lajos Arpad

你的防護體可以被描述成:

(X - X1)^2+ (Y - Y1)^2= R^2

發射體的路徑線可以描述為:

Y - Y3 = ((Y4 -Y3) / (X4 - X3)) * (X - X3)

從這里:

Y = ((Y4 - Y3) / (X4 - X3)) * (X - X3) + Y3

用上述拓展第一個方程,得到:

(X - X1)^2+ (((Y4 - Y3) / (X4 - X3)) * (X - X3) + Y3 -Y1)^2= R^2

這是一個 二次方程 ,如果解決則能給出交點的X值。閱讀鏈接中的二次方程解決方案,它將用一個公式獲得第一個脈沖來解決問題。當然,如果判別式為負,就沒有交點,那么方程式就沒有真正的答案。如果判別式是0,那么發射體就會觸碰到防護體。如果判別式為正,那你就獲得了答案,用方程式的結果退出X。

知道了X的值之后,就可以計算用下面的公式計算Y的值。

Y = ((Y4 - Y3) / (X4 - X3)) * (X - X3) + Y3

最后注意,只有在發射體的路徑線不是垂直的才能夠起作用,因為那樣X4就等于X3,導致基本方程無用。當出現發射體穿過一條直線的情況下,線的公式為:

X = X1

然后使用公式:

Y = ((Y4 - Y3) / (X4 - X3)) * (X - X3) + Y3

來獲得可能的解決方案。(再次聲明,這是一個二次元方程)

所以這一執行應該檢查發射體的路徑線是否垂直,然后根據具體情況選擇相應的解決方案。希望這能幫到你。

原文鏈接:Detecting possible projectile vs shield collision

 

文章選自StackOverFlow社區,鑒于其內容對于開發者有所幫助,現將文章翻譯于此,供大家參考及學習。9Tech將每日持續更新,讀者可點擊StackOverflow(簡稱:SOF)精選問答匯總,查看全部譯文內容。同時,我們也招募志同道合的技術朋友共同翻譯,造福大家!


建議使用電驢(eMule)下載分享的資源。

說明
:本教程來源互聯網或網友分享或出版商宣傳分享,僅為學習研究或媒體推廣,51zixue.net不保證資料的完整性。
 
上一篇:Unity 相關經典博客資源總結  下一篇:用Unity3D 開發游戲哪種語言最好?
彩客网 www.83033m.com | www.hg0204.com | www.rfdc01.com | shen5544.com | www.dhy35.com | www.49956k.com | 6261ww.com | www.js410.com | www.869619.com | zb129.com | www.00773v.com | www.55885a.com | www.laok222.com | www.ihg5511.com | yh77.com | www.5966mmm.com | www.371931.com | 97659.com | www.688sb.21.sb | 56987ll.com | www.jszg22.com | www.876928.com | 2509.com | www.68682g.com | 66671.com | www.811202.com | 8449hb.com | www.288kb.net | www.50052g.com | p67890.com | www.115527l.com | stsvip9.com | www.xin006.com | www.16065g.com | so88888cc | www.sha2244.com | fff01234.com | www.hg4799.com | www.577972.com | www.6033t.com | www.3416q.com | 33382h.com | www.hg0296.com | 8037w.com | www.55070p.com | 8520g.com | www.66050.com | www.335294.com | www.60088hg.com | www.5086s.com | df8z.com | www.77114y.com | j3405.com | www.2350.vip | xd2016.com | www.50685c.com | 469.com | www.64566f.com | 3522nn.com | www.xm9900.com | 3544.am | www.063263.com | 67890ppp.com | www.998855w.com | 5509m.com | www.4041.cc | 8940.com | www.ggv.99233v.com | h4255.com | www.258suncity.com | 51335e.com | www.3846l.com | 12580088.com | www.60886.com | 30019dd.com | www.910655.com | 0559688.com | www.93gj01.com | js5011311.com | www.68cc1.com | 8449qq.com | www.32123s.com | 9030s.com | www.898338.com | www.as0008.com | www.364141.com | www.uu0096.com | 1259d.com | www.pj5719.com | 29918hh.com | www.56655r.com | 606469.com | www.bet63w.com | 0638.com | www.a2418.com | 922630.com | www.cha62.com | www.7979w.net | www.61655u.com | www.9374i.com | 80850o.com | www.bwinyz34.com | yh66555.com | www.71399t.com | www.qy324.com | www.033918.com | www.64566j.com | z14666.com | www.56011r.com | vip99550.com | www.937150.com | www.330099w.com | 9411nnn.com | www.57800c.com | 7003z.com | www.022xz.cc | www.144676.com | 38455.com | www.07679h.com | 21488app.com | www.926730.com | www.66am4455.com | 80368oo.com | www.am57877.com | zhcpqq.com | www.856657.com | www.wn99yyy.com | h3410.com | www.087n.com | www.k8.com | www.186357.com | www.11132.com | 9030a.com | www.46976.com | www.xw111111.com | x86006.com | www.b35ww.com | rr3405.com | www.c4534.com | www.9679y.com | hg8355.com | www.8008553.com | 9030k.com | www.455598.com | www.jl708.com | 999649.com | www.506953.com | www.rycp160.com | 5004xx.com | www.802533.com | www.81789.com | 3640tt.com | www.400322.com | www.137603.com | dzc05.com | www.5220666.com | b8381.com | vn8940c.com: | www.57366b.com | www.kima99.net | s4255.com | www.77427.com | www.9068cc.com | 5369z.com | www.33112d.com | www.1233789.com | 4136q.com | www.775701.com | www.6664ylg.com | 866666z.com | 34g35.com | www.831666.com | www.xpj88004.com | 2021a.com | www.661661a.com | www.cp67772.com | 111122xx.com | xh00020.com | www.67258b.com | www.yh400000.com | 11005b.com | 66648m.com | www.60wb.top | www.82627.com | 54141177.com | hr1800.com | www.2875n.com | www.081355.com | 3178jj.com | 3522t.vip | www.7782v.com | www.77731s.com | k2554.com | 7335t.com | www.29178f.com | www.zte333.com | x87.com | 111122gg.com | www.hx7766.com | www.cn365m.com | www.365109e.com | 3066aaa.com | www.567106.com | www.77789yh.com | www.hg246.com | 66185a.net | 500c.vip | www.al5888.com | www.w1432.com | www.7025o.com | c40033.com | 99151h.com | www.3479x.com | www.bwinyz09.com | www.7111o.com | 48611.com | 1463l.com | www.500713.com | www.570337.com | www.hg8449.com | zhcp40.com | v997e.com | www.028314.com | www.78700n.com | www.888.ps | www.454.net | 99589q.net | hg1688l.com | www.560259.com | www.950058.com | www.lfcp111.com | www.wns8828.com | 55967d.com | 365225.tw | www.809573.com | www.9996ee.com | www.79500k.com | www.7025k.com | dzc94.com | 496.bi | g32365.com | www.ya619.com | www.7886262.com | www.C63.COM? | www.8577k.cc | www.jsh955.com | kbv8832.com | 40014499.com | 0077buyu.com | www.799436.com | www.bet365yazhou.com | www.4446ccc.com | www.ylg122.com | www.1869t.com | df8v.com | 78930006.com | 7335t.com | www.djcp002.com | www.25czj.com | www.37377t.com | www.yy17173.com | www.245899.com | www.9996ww.com | 4195hh.com | 6150k.com | 72vg.com | 1777ca.com | 36408811.com | mgbet.vg | www.206883.com | www.clh1.com | www.43818j.com | www.575477.com | www.4058ss.com | www.29msxfptc.com | www.110978.com | www.22832333.com | www.68666c.com | f2870.com | 4022vv.com | 00ww8331.com | vns.com | 3258e.com | 8722rrrr.com | 35tt.vip | www.51515v.com | www.501203.com | www.816820.com | www.7dzh.com | www.tang444.com | www.29277p.com | www.7714f.com | www.2418z.com | www.99094b.com | www.60886.com | www.7225f.com | www.71071d.com | www.509029.com | www.5487.com | www.bet3650914.com | www.9103ss.com | www.88837a.com | www.9068qq.com | www.7380pp.com | www.7669d.net | www.ks883.net | www.pjgansu.com | www.98698i.com | jsdas8.com | 2015.com | ddd5657.com | www.czg1.com | www.162090.com | 2021www.com | 655660033.com | www.hg97hg.com | www.5457.com | www.6889793.com | www.751898.com | mgm3242z.com | wlb11.com | www.yh03456.com | www.a81p.cc | www.110272.COM | www.326366.com | 12742z.com | 83138d.com | www.8522cn.com | www.18955.bet | www.1368a.cc | 20776688.com | 2127x.com | www.aomen8866.com | www.huangma21.com | www.2109h.com | jxddcs.com | 1294w.com | www.56520y.com | www.9b001.com | www.32123q.com | bet28h.com | xxx01234.com | www.006087.com | www.xpj1123.com | www.710230.com | 684526.com | 57157g.com | www.bmw111.com | www.77801g.com | 70118x.com | 3726m.com | www.2846d.com | www.js89r.vip | www.lg7717.com | 87578004.xyz | www.yh8210.com | www.4058k.com | www.c760.net | 53262e.com | www.bh11234.com | www.19019v.com | www.qbwc2.com | 78110077.com | www.jbb2015.com | www.7bet005.com | www.930557.com | p005.com | www.www--97828.com | www.1754a.com | www.544779.com | 211707.com | www.88837x.com | www.flb577.com | nn500i.com | 55331.com | www.3171110.com | www.9818v.cc | 8855670.com | www.js46123.com | www.jsdc9222.com | 7196hh.com | hgyz33.com | www.601066.com | www.775790.com | 3389.live | www.66136cc.com | www.62118b.com | 4066bb.com | www.33366638.com | www.8577f.cc | 2776p.com | 365058.com | www.b80288.com | www.393890.com | 49964.com | www.567811.com | www.2350p.com | haocaipiao.net | www.hg663.com | www.80075n.com | 2021ddd.com | www.9068aa.com | www.xj112233.com | 6175ss.com | www.00829l.com | www.xy52aa.com | bet365ok04.com | www.bet3650514.com | www.186664.com | 8577r.cc | www.7830j.com | www.16188a.com | 88894f.com | www.118893.com | www.3933u.cc | 4288ii.com | www.138msc.com | www.629813.com | 73055d.com | www.5981m.com | www.41518o.com | 37570t.com | www.32031v.com | 0638.cn | www.4107p.com | www.77803t.com | 57bet.cc | www.js600000.com | www.341977.com | zhcp76.com | www.40288t.com | 3522ss.cc | www.566333.com | www.89911.cc | 01234nnn.com | www.4136f.com | xbo198.com | www.6491z.com | www.84499r.com | 0033buyu.com | www.68277555.com | www.106036.com | 121ccc.com | www.6939d.com | 55797y.com | www.hg4799.com | www.513477.com | 6868nn.cc | www.7388101.com | ww0332.com | www.79500d.com | 16690055.com | www.3643m.com | www.gai00.com | 3308a.com | www.xpj3123.com | 59599.com | www.79111bb.com | www.106195.com | www.z0888.com | www.81520.com | bet37544.com | www.blr1144.com | 2820o.com | www.k456x.com | 99559193.com | www.358955.com | www.354177.com | www.lhg555.com | www.3668w.com | 3522b.vip | www.97828z.vip | 0198855.com | www.38138n.com | chinajtw.com | www.zte888.com | 168cp-a.com | www.701439.com | www.202901.com | www.20909l.com | www.872198.com | www.86611a.com | www.3126w.com | 082371.com | www.87668m.com | 6868269.com | www.954321n.com | 4107c.com | www.86333b.com | 82365t.com | www.w63568.com | 7003t.com | www.hg7112.com | 316k.cc | www.087g.com | 3506.com | www.0194004.com | 54241111.com | www.ya2019d.com | v1931.com | www.113744.com | 55331ll.com | www.16878u.com | gao482.com | www.89338.com | 2649dd.com | www.3552x.com | qq88688.com | www.971261.com | www.333222w.com | www.570133.com | www.777444j.com | www.010956.com | www.448809.com | 1429m.com | www.c1724.com | 59599.com | www.678js222.com | 53358q.com | www.89777a.com | 05877.com | www.ya390.com | www.38200r.com | www.331277.com | www.31268.com | 7141xx.com | www.58118f.com | 3678nnn.com | www.365003.cc | 131h.net | www.895465.com | www.0860v.com | 846015.com | www.1168q.com | 78666t.com | www.hg2300.com | pj08444.com | www.cp8009.cc | www.g0041.com | 56033.net | www.19019y.com | 8522yyyy.com | www.60798.com | 5429u.com | www.373970.com | www.245899.com | 1389ee.com | www.1434y.com | 2844n.com | www.632599.com | www.hg7684.com | 1463p.com | www.75600b.com | 2649s.com | www.599091.com | www.078tk.com | 36989d.com | www.038839.com | 9195js.com | www.66652o.com | www.tyc131.com | 957939.com | www.7515aa.com | www.88837z.com | 4812q.com | www.7920o.com | 2418y.com | www.225065.com | www.039907.com | 4488r.com | www.2tdc.com | www.8996hh.com | 67890u.com | www.99788k.com | www.js46123.com | 4136e.com | www.0044sun.com | wns940.com | 0730000.com | www.185141.com | 69096g.com | www.330637.com | www.50999h.com | 6261q.com | www.606614.com | www.zte888.com | 40033hhh.com | www.710650.com | www.dy4488.com | 8569844.com | www.684344.com | www.138cps.com | 009207.com | www.399146.com | www.19019n.com | cc2205.com | www.26878e.com | www.45598w.com | 8827a.com | o72227.com | www.883399d.com | www.1636001.com | 55443885.com | www.hb858.net | www.777444p.com | 991682.com | www.7116b.com | www.359812.com | 4541d.com | www.503489.com | www.59199.com | jsjlb99.com | 61652h.com | www.8998887.com | www.c30226.com | 3379j.com | www.ch8933.com | www.c44ff.com | 4695599.com | 4116d.com | www.99094i.com | www.3643e.com | 58885365.com | www.996863.com | www.50999g.com | 2019l.cc | l2649.com | www.7793n.com | www.626suncity.com | 2383qq.com | 4195cc.com | www.91233hh.com | www.800hm.com | 88851j.com | 0116556.com | www.46976.com | www.wns47.com | a2146.com | 29918l.com | www.89777t.com | www.4778.com | 6766vv.com | 4992535.com | www.77801y.com | www.133004.com | zhcp05.com | 8881240.com | www.111xm.cc | www.7415rr.com | www.ylg888888.com | 500000355.com | www.609710.com | www.58908a.com | www.sbet345.net | 3568oo.com | 36518.info | www.83033h.com | www.tyc8879.com | 4255mm.com | 9068f.com | www.544779.com | www.836bbb.com | www.blr795.com | 6261v.com | sbf533.com | www.926013.com | www.88325o.com | www.hg1733.com | 20550452.com | 37570z.com | www.865065.com | www.86339o.com | www.wd00004.com | k2306.com | hg8081.com | www.257188.com | www.dy964.com | www.9999d.com | www.32126r.net | 8344aa.com | 5647s.com | www.c300.vip | www.js58111.com | www.89456.com | 11422r.com | 9068ll.com | 6a6a.com | www.773976.com | www.v774477.com | www.yhgjk.net | www.0636c.com | 9068ff.com | 78116655.com | www.526013.com | www.89888.com | www.47751.net | www.2078c.com | 2355h.com | 0008.io | 66449193.com | www.689244.com | www.188666.com | www.5446zz.com | www.pj990.com | 5004ss.com | 4288n.com | v9330.com | www.196556.com | www.51876.cc | www.xpj716.com | www.3846j.com | www.330099u.com | bb8888-3.com | 4036n.com | 55229193.com | 44ff8332.com | www.676944.com | www.83033k.com | www.73990t.com | www.4719aa.com | www.msc55.com | 1346.com | 5am.vip | 65561177.com | tyc.com | www.167918.com | www.65yb.com | www.pj56k.com | www.6687x.com | www.063260.com | www.13558u.com | www.68666f.com | 4647b.com | gg3336.com | 626920.com | 3730-90.com | www.5854d.cc | www.68203dd.com | www.8645003.com | www.68277666.com | www.446677.com | www.76543x.com | 7335z.com | yhjiangsu.vip | 888992255.com | 2767f.com | 13222a.com | mgm3242a.com | www.155091.com | www.843980.com | www.3933b.cc | www.0066wd.com | www.blr3344.com | www.7225a.com | www.38345m.com | www.blr336.com | www.901008.com | www.3643n.com | www.hg990022.com | 51200oo.com | 0600n.cc | 08820088com | 3467l.am | j01234.com | 6777.org | 4995q.com | ff555n.com | zunyi18.com | 4833011.com | 2506h.com | 1408t.com | www.96386u.com | www.351857.com | www.585116.com | www.795335.com | www.995168.com | www.qmkl6.com | www.6364b.com | www.35918n.com | www.0270w.com | www.304005.com | www.557466.com | www.48330k.com | www.1434d.com | www.xpj8118.com | www.pjc66.vip | www.44118h.com | www.vnsr638.com | www.63606l.com | www.4521v.com | www.xpjylc008.com | www.9895d.com | www.ag3344.com | www.776887.com | www.40288d.com | www.js89b.vip | www.7920q.com | www.8083.am | www.pgylc.cc | www.518pj.com | www.83993b.com | www.54400n.com | www.15355g.com | www.5095g.com | www.ya989.com | www.987436.com | www.771745.com | www.580780.com | www.303464.com | www.29178e.com | 2643u.com | 80567s.com | ule609.com | 2247k.com | b40033.com | yl6896.com | 7454jj.com | yin1044.com | www.14555a.com | www.655666a.com | www.yh22778.com | www.20201.com | www.a81c.cc | www.22vn777.com | www.3421m.com | www.55545k.com | www.54400f.com | www.2tdc.com | www.579031.com | www.36166e.com | 35.vip | 8884136.com | 5856www.com | 55797f.com | 3938.com | www.39695b.com | www.64566t.com | www.ssc8871.com | www.pjgw66.com | www.68993238.com | www.16878g.com | www.955334.com | www.155091.com | 131nn.net | 822063.com | m3410.com | 2643n.com | www.76543o.com | www.julongjy888.com | www.705905.com | www.5446p.com | www.81678m.com | www.901025.com | b5313.com | uu1916.com | 32666a.com | 2776t.com | www.bet3652018.com | www.pj7686.com | www.n32939.com | www.55717g.com | www.068wy.com | www.270667.com | 3467a.com | 6002n.com | 9949c.com | www.hg0112.com | www.03tyc.com | www.60886c.com | www.50732c.com | www.533292.com | 11.net | 4590r.com | 2211760.com | www.2002900.com | www.89599c.com | www.16065l.com | www.771049.com | 55797l.com | 3950u.com | z88rr.com | www.pj7686.com | www.35252a.com | www.34788z.com | www.193722.com | 27365e.com | 26668n.com | www.4625i.com | www.ggu.99233u.com | www.81608i.com | www.901576.com | zz.org | 55323d.com | www.8n8.com | www.jw799.com | www.585721.com | www.781367.com | 4444sands.com | toucai66.com | www.hg4030.com | www.83568y.com | www.26163e.com | www.195090.com | dq25.com | 3016ccc.com | www.1f888.com | www.765703.com | www.767200.com | 0853dh.com | wlb44.com | www.h896.com | www.w84v.com | www.959122.com | 125588.com | hg0099e.com | www.9956699.com | www.07679y.com | www.922069.com | 55cc.com | 016458.com | www.8148.com | www.4809s.com | www.542676.com | qijiduchang.com | 1389tt.com | www.jxcp3333.com | www.96386y.com | sxlwl.net | dd01234.com | www.58777q.com | www.79095r.com | www.853689.com | 7335f.com | 4066ll.com | www.c555.cc | www.5095b.com | 7196a.com | 8036t.com | www.43282.com | www.820808.com | 23800n.com | 6766.com | www.0977711.com | www.662365.cc | www.89894e.com | 4156.com | www.ccc665.com | www.h6610.com | 29918l.com | 400089v.com | www.66458v.com | www.vip332.com | 0747o.com | 0208077.com | www.912006.com | www.23579c.com | 1479l.com | 953644.com | www.04567h.com | www.849642.com | 77ee940.com | www.777444h.com | www.flb177.com | 188711.com | 7720.net | www.a9151e.com | www.77fzc.com | 线路1005.com | www.3xinhao.com | www.490802.com | www.099323.com | tcdtf.com | www.988806.com | www.2350l.com | 56978.com | www.hg0095.com | www.087n.com | 33zz8332.com | spj09.com | www.71071w.com | www.599487.com | m01234.com | www.9426.com | www.371p.cc | i86811.com | www.330099v.com | www.081234.com | 68ps.com | www.90866.cc | www.86339.com | x62365.com | 33115jj.com | www.30k0048.com | www.235944.com | 00cc8331.com | www.28000r.com | www.573678.com | 50099.com | www.039907.com | www.589021.com | 8988p.com | www.8865tt.com | www.517602.com | 00ee8331.com | www.98698k.com | www.452823.com | 77002007.com | www.89599w.com | www.219055.com | 56988q.vip | www.3066ll.com | js7001.com | 3121cc.com | www.837929.com | 3983012.com | www.hg2218.com | www.8582pp.com | 45637x.com | www.huangguan1088.com | www.16878g.com | yth67.com | www.0409.com | www.652188.com | hg77702.com | www.h69096.com | 22291166.com | www.3aobo.com | www.js07678.com | 2019.cc | www.9997068.com | www.876061.com | fll8.in | www.4521e.com | 0033p.cc | www.hg5801.com | www.2632m.com | 8159lll.cc | www.1064b.com | 8827aa.com | www.32126s.net | www.52072j.com | 3957g.com | www.9ccp22.com | 033e.net | www.vn89969.com | www.55885g.com | 1422.cc | www.4212b.com | 55557893.com | www.alpkylc.com | www.4189b.com | 3775.com | www.87708e.com | 90307l.com | www.zrdc2277.com | www.711853.com | 3009o.com | www.hg15588.com | 8015z.com | www.58665a.com | 301111.com | www.09569s.com | www.c136.vip | 44077o.com | www.8998799.com | 597929.com | www.365033.bet | hv712.com | www.99951144.com | www.617787.com | yl77yl33.com | www.66376k.com | 8037rrr.com | www.6386c.com | 44339193.com | www.107015.com | 3434b.com | www.274166.com | www.214654.com | www.570166.com |