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 開發游戲哪種語言最好?
彩客网 9439922.com | mm99900.net | tgf8876.vip | 8381006.com | www.298345.com | www.34kj.com | www.2418u.com | www.52062k.com | www.lczg8.com | www.130511.com | 73567tg3.com | www.28758h.com | www.msc-msc.com | www.3846cc.com | www.955381.com | 2535b.com | 8538m.com | www.am0676.com | www.xfc88.com | www.80767l.com | www.357173.com | 93936t.com | 61328822.com | www.166663.com | www.13434e.com | 777hg333.com | mm99900.net | www.1230404.com | www.aaa2848.com | www.808482.com | 1770r.com | 44488d.com | www.hg3115.com | www.7239l.com | 99bjlxz.com | 38850011.com | www.429978.com | www.16065j.com | 11992007.com | 8905j.com | www.cp77dd.com | www.66376hh.com | 22291166.com | www.qy858.com | www.4963ll.com | www.2373d.com | yyh910.com | www.sbd444.net | www.8080999b.com | www.196050.com | 3405sss.com | www.77537q.com | www.490803.com | www.501347.com | 5622u.com | www.00618x.com | www.502206.com | bet3659091.com | feicai0354.com | www.pj66119.net | www.911203.com | 3788nn.com | www.77595g.com | www.683909.com | 5589k.com | 7008037.com | www.pjc00.vip | 5804m.com | 7935r.com | www.00778n.com | www.560702.com | hg10f.com | www.tm71.com | www.507670.com | 3016sss.com | www.89.cc | www.cp3.mobi | 4340o.com | www.49200a.com | www.722563.com | w4255.com | www.35252n.com | www.975367.com | 95c53.com | www.39695q.com | www.js02346.com | 55119193.com | www.xhf5555.com | www.33112k.com | 6556e.com | www.pj88137.com | www.58870t.com | 4116w.com | www.777758.com | www.582477.com | 23800e.com | www.6768997.com | 2822828228.com | 209899.com | www.ampj3432.com | rrr5657.com | www.hjcp66.com | www.377613.com | 5214v.com | www.3507777.com | 61999ff.com | www.xj4466.com | www.738070.com | 87578y.bet | www.068633.com | yl66yl44.com | www.848777r.com | 6150d.com | www.77537x.com | www.890703.com | 8722ffff.com | www.bet73i.com | 019dh.com | www.k00444.com | n45638.com | www.56520x.com | www.809381.com | js456456.com | www.jcai1.com | 5589e.com | www.36587777.com | 55331ss.com | www.44118o.com | xinpj1600.com | www.52564.com | www.500103.com | www.v0070.com | www.15355b.com | 22299bb.com | www.886498.com | sss4255.com | www.742488.com | 69111u.com | www.7415k.com | 888991155.com | www.8833tm.com | 6a6a.com | www.849999c.com | 77778940.com | www.163a6.com | hkmh88.com | www.3533msc.com | 8827jjj.com | www.fc841.com | 3788m.com | www.56655q.com | 3122mm.com | www.91w.com | blr878.com | www.s32939.com | yh996.vip | www.7415kk.com | 3189e.com | www.w84w.com | 7599qq.com | www.16065j.com | 3169z.com | www.66ffo.com | 0747j.com | www.26199.com | 15a38.net | www.l9478.com | 8118522.com | 4136p.com | www.3668q.com | www.848777a.com | www.004439.com | 2247f.com | 3178811.com | blm800.com | www.c6129.com | www.615069.com | www.79500j.com | www.y5777.com | dh4546.com | 9339999z.com | 1294z.cc | 2233blg.com | ylg5888.com | www.810575.com | www.33588h.com | www.hg355.com | www.621051.com | www.88166h.com | www.899111.com | www.3002229.com | www.xh5111.com | zzc55.com | 3566cc.com | js02.app | 3334661.com | 78115588.com | 50128.vip | www.336766.com | www.590791.com | www.c129.vip | www.ac9911.com | www.5854r.cc | www.26299b.com | www.78949x.com | www.pj56j.com | www.6880ww.com | www.80188e.com | www.3893k.com | www.4645555.com | www.bet3652018.com | 3544i.com | feicai0734.com | 500000914.com | 0747y.com | df8kk.com | 00443015.com | 2649y.com | 883399a.com | 3178tt.com | 057360.com | 37570a.com | 35252n.com | 6868ll.cc | 1479e.com | zhcp32.com | 272k.net | 866bc.com | www.3435333.com | www.y5578.com | www.05a88.com | www.995055.com | www.vip22252.com | www.3459r.com | www.fh8000.com | www.35359193.com | www.k66111.com | www.222741.com | www.850750.com | www.mhcp.com | www.8080999b.com | www.6889797.com | www.32365.Com | www.6611b.cc | www.586031.com | www.137105.com | baizun456.com | bet28.com | 66648u.com | 0805p.com | jj1915.com | 0229422.com | 3016.com | www.xin777888.com | www.v15542.com | www.45778.com | www.rb362.com | www.c668ln.com | www.10999l.com | www.xpj16682.com | www.606010.com | www.8039k.com | www.700590.com | www.29277i.com | 08530005.com | 131bbb.net | 22890.co | 2146d.com | ff555c.com | www.twcp999.com | www.82799b.com | www.tyc723.com | www.r3410.com | www.zpw100.com | www.61655j.com | www.55cmc.com | www.330197.com | 10jqka.com | byc888b.com | 4340bb.com | d2649.com | www.hg1767.com | www.84786.com | www.bet63i.com | www.0601j.com | www.443300a.com | x48x.com | 8448002.com | 88807v.com | www.9068vv.com | www.666suncity.com | www.04567f.com | www.52062c.com | www.0014a.com | www.77801a.com | 500000471.com | 67890hhh.com | www.817558.com | www.js276.com | www.4bet005.com | www.m77929.com | www.585065.com | bet89226.com | 68228q.com | www.67797m.com | www.lfcp095.com | www.048.com | www.925771.com | 88559193.com | 3726v.com | www.pjfujian.com | www.11223885.com | www.860505.com | www.luck818.com | 66287r.com | afcp09.com | www.86611f.com | www.tushan68.com | www.38358.com | www.661023.com | xpj90618.com | 33vv8332.com | www.ra8804.com | www.5700666.com | www.cai345.cc | 58222aa.com | 82299.com | www.5590777.com | www.b83377.com | www.sjgc2.com | 3066aa.com | g61653.com | www.677100.com | www.8645001.com | www.qucw7.com | 11422.com | tour76.com | www.70337.com | www.hr255.com | www.530891.com | youfa111.vip | 6403b.com | www.80074.com | www.50026c.com | www.178693.com | vns33.me | www.h7788e.com | www.79095y.com | www.729198.com | pj8114.com | c51ki64.com | www.hjcp2.com | www.50989f.com | 365225.com | 0747mm.com | www.7335xx.com | www.32123m.com | 9971008.com | 2019c.cc | www.1196877.com | www.igcp3.com | 04666x.com | www.0686222.com | www.15365d.com | www.855608.com | 2190b.com | www.8804js.com | www.mgm868006.com | www.662517.com | 444000ff.com | www.83008z.com | www.79670.com | 77778940.com | ziz3.com | www.733486.com | www.196095.com | 4541i.com | www.pj238.com | www.49956q.com | 22556l.com | www.xpj4444.cc | www.7191a.com | www.77803v.com | 80850jj.com | www.sj52488.com | www.938454.com | 8006010.com | www.js60a.com | www.99788q.com | 32126n.net | www.ys0022.com | www.bb888.cc | 131xxx.net | www.hg39899.com | www.3846ff.com | 87965xx.com | 6363ss.com | www.3032hh.com | 111356.com | 55vn77.com | www.32031f.com | 11tt8331.com | www.6033o.com | www.42070013.com | 9498.com | www.b27229.com | www.115966.com | 6600mmmm.com | www.yy085.com | www.7782b.com | 01234t.com | www.1155025.com | www.770951.com | wlb33.com | www.2y929.com | www.570831.com | ued.bet | www.1429e8.com | 4023w.com | www.yh66609.com | www.1237777.cc | 234902.com | www.365v06.com | www.99jtd.com | yyy909.com | www.c75.cc | www.81520o.com | 91019w.net | www.7886266.com | 6594zz.com | www.456228.com | www.817336.com | 8381s.com | www.669112.com | js88830.com | www.hg00111.com | www.lfu8.com | 1483zz.com | www.38138c.com | www.43131d.com | www.936699.com | www.99099hh.com | lh66v.com | www.500cp.cc | 4774r.com | www.2846j.com | www.c2808.com | wnsr8807.com | www.1434x.com | y2523.com | www.412666.com | www.447478.com | 60266.com | www.77803l.com | 3482z.com | www.5189555.com | 3616y.com | www.88984.com | www.208990.com | 38989o.com | www.91233m.com | t1915t.com | www.60886e.com | 4809s.com | www.58665p.com | 5437n.com | www.3775778.com | www.363067.com | www.kj638.com | www.19kpl.com | qycp05.com | www.4323o.com | 51335n.com | www.4102y.com | 73222.com | www.hjdc2005.com | t365f.com | www.97060d.com | biwei116.com | www.85857s.com | 79889q.com | www.hg56555.com | www.218565.com | www.67797r.com | www.629813.com | www.38200g.com | www.921599.com | 1119193.com | www.34489.cc | k35151.com | www.8816r.com | 500000514.com | www.36829.com | 2709b.com | www.2350y.com | 7js345.com | www.622by.com | 2127m.com | www.60007q.com | xg9111.com | www.28czj.com | www.a2a444.cc | www.098wy.com | j15hh.com | www.826552.com | www.995055.com | www.466780.com | www.718msc.com | www.030628.com | www.21050022.com | 8988a.com | www.339879.com | 2851t.com | www.30hga.com | 56988yy.com | www.js89l.vip | hga088.rs | www.25688i.com | 2776n.com | www.925771.com | www.7380m.com | www.96386u.com | www.pj98914.com | 28758.com | www.38138s.com | 3559ff.com | www.bet353657.com | 2776n.com | www.803242.com | www.25288s.com | 7945ww.com | www.31148.com | 2941122.com | www.6889775.com | 11989n.com | www.767198.com | www.546suncity.com | www.33598i.com | www.2945h.com | 8569811a.com | www.vip5888.com | 21866d.com | www.444246.com | www.203477.com | 5429i.com | www.69989f.com | 3522m.cc | www.2934h.com | www.10053344.com | yl2827.com | www.hgdc900.com | 32yxw.com | www.965160.com | www.xb0029.com | 56987nn.com | www.2299nsb.com | 3189vip.com | www.500871.com | www.397888b.com | 33432x.com | www.89338c.com | www.63877i.com | x5039.com | www.678js555.com | 2805e.com | www.504638.com | www.988778.com | 4005dh.com | www.00840w.com | www.vns2365.com | aa7742.com | www.6889783.com | www.63260.com | 7935a.com | www.y0291.com | 28758x.com | www.095069.com | www.5446zz.com | 01885u.com | www.549677.com | www.cfcp789.com | 86226q.com | www.976921.com | www.3066037.com | m1915m.com | www.cp58.biz | www.msc855.com | 4340s.com | www.825126.com | www.jy959.com | 20160913.vip | www.477680.com | www.6776cc.com | 5443r.com | www.051069.com | www.7225s.com | 2373o.com | 06385050.com | www.1434t.com | www.63877d.com | bwin68888.net | www.365.tv | www.776577.com | 889q.net | www.cpkk7.com | www.16602i.com | 2jsyyy.com | www.364141.com | www.bet63j.com | 6002m.com | ff555i.com | www.12455v.com | www.hg6888.com | l99474.com | www.726703.com | www.16181i.com | yh888e.com | 3565.com | www.33997w.com | www.28686.com | 2127tt.com | www.399957.com | www.7225f.com | www.wns8848.com | 4546vip2.com | www.hy5503.com | www.848434.com | 0600o.cc | 505ooo.com | www.7782n.com | www.2y934.com | ddd2267.com | 2820q.com | www.50052z.com | www.sb8841.com | uc02.cc | 3434b.com | www.77802k.com | www.am4567.com | 6572m.com | 9103rr.com | www.39957g.com | www.jgj230230.com | 500000794.com | 1591911.com | www.3478o.cc | www.4972g.com | www.yyhbet6.com | s67890.com | www.828516.com | www.6386d.com | www.58777b.com | 4114.com | aa33339.com | www.60123r.com | www.c44rr.com | 1408o.com | 2649aa.com | www.452815.com | www.62778822.com | www.ao2016.com | 9995k.cc | 71366l.com | www.676477.com | www.792071.com | www.66318t.com | 000000oe.cn | 500000393.com | www.cp3.mobi | www.78680q.com | www.84859.com | qycp10.com | bwinkkkcom | www.371931.com | www.js00858.com | www.005mgm.com | www.81866a.com | 4455634.com | 390626.com | www.6022888.com | www.ra0008.com | www.238267.com | 4231.com | 6175c.com | www.934689.com | www.b3846.com | www.666089.com | 84844001.com | 3559hhhh.com | p332.com | www.775377.com | www.68993225.com | www.hemi168.com | www.l32126.cc | 3967v.com | 3678zz.com | www.444019.com | www.bet73m.com | www.89599d.com | www.42842814.com | 2506i.com | 8988222.com | 3121q.com | www.773618.com | www.3066.com | www.7415x.com | www.77ff940.com | 9149c.com | 3467z.com | 500000377.com | www.506586.com | www.71233p.com | www.v1432.com | www.3844zz.com | www.pjbet666.com | 3016sss.com | 83138m.com | 212300.com | www.504733.com | www.85090.com | www.12136f.com | www.lfcp097.com | www.hg1668.com | 6137.com | 8722ssss.com | ambjl.cc | 88447.com | www.606187.com | www.109337.com | www.377666f.com | www.990654.com | www.32666i.com | 7196zz.com | 8547y.com | hg0266.com | pj88cc.com | www.153328.com | www.cp8017.cc | www.550021j.com | www.js89k.vip | www.5596877.com | www.1817.cc | www.330099x.com | b5369.com | 0747nn.com | 8159jjj.cc | 66300vip12.com | 8159z.cc | 518cp8.com | www.330817.com | www.hf0666.com | www.67258b.com | www.db486.com | www.2544g6.com | www.9b009.com | www.hp5868.com | www.am1818.cc | www.365815d.com | www.580583.com | 2820y.com | 13558.com | 3834505.com | 56787gg.com | 8547mm.com | 1114116.com | 97799g.com | 22bb8332.com | www.76520u.com | www.444246.com | www.686244.com | www.979133.com | www.00tdc.com | www.07163c.com | www.00840a.com | www.sdsy.com | www.550022.com | www.pj55717.com | www.33678ss.com | www.4996gy.com | www.pj88o.com | www.808888y.com | www.cs.bet | www.wxc0234.com | www.520068.com | www.257js.com | www.amxj8855.com | www.155a56.com | www.vns9603.com | www.v15541.com | www.9679i.com | www.5364d.com | www.588sun.com | www.87680a.com | www.3459g.com | www.76543w.com | www.d276.com | www.pj15778.com | www.41msc.com | www.2846k.com | www.js13777.com | www.67223g.com | www.hg50668.com | www.97321f.com | www.423886.com | www.82205.com | www.hg8907.com | www.55526h.com | www.1168i.com | www.z32939.com | www.i80288.com | www.30350r.com | www.56011b.com | www.55717g.com | www.zzyl63.com | www.180662.com | www.39957c.com | www.20czj.com | www.852086.com | www.533551.com | www.068653.com | 98955i.com | c2554.com | 18438s.com | 78118833.com | 4465v.com | 2127zz.com | 500c32.com | www.o168a.com | www.7893w54.com | www.82894w.com | www.8yw.net | www.e32939.com | www.3032ff.com | www.68993257.com | www.68568g.com | www.ybao7.com | www.570133.com | www.35155v.com | 7726ddd.com | 38818.com | 3522m.cc | mgm3242.net | www.xh9111.com | www.wns8833.com | www.hj829.com | www.4078u.com | www.56011v.com | www.98528c.com | www.ascp3.com | www.276608.com | feicai0379.com | 55119193.com | 3807yy.com | 9895s.com | www.25673b.com | www.hg3756.com | www.b526688.com | www.839282.com | www.hv866.com | www.55070z.com | www.23456789.pw | www.07163y.com | www.456586.com | 91019z.com | 4270yy.com | 444000n.com | www.bet365789.com | www.xg289.net | www.xycp98.net | www.hg873.com | www.hx1181.com | www.52072q.com | sha9909.com | 992222m.com | 0080j.com | www.60688store.com | www.79500k.com | www.99094g.com | www.88yfa.com | www.082965.com | 6446vip.com | youfa777.vip | www.9374g.com | www.sb8841.com | www.0600f.cc | www.3416p.com | www.025728.com | 78114411.com | v8738.com | www.p76888.com | www.b8444.com | www.106a56.com | www.dqz7.com | 8988rr.com | 5019kze.com | 2019q.cc | www.ao2016.com | www.1183066.com | www.2632z.com | 58802q.com | 2172288.com | pj677x.com | www.577444.com | www.js89i.vip | www.33gpc.com | 7792o.com | 4488qqq.com | www.682855.com | www.721408.com | www.37377i.com | www.616383.com | 2229822.com | 55188.com | www.ff13558.com | www.4521.com | www.qucw3.com | 377633.com | 800089v.com | www.21365hh.com | www.55070l.com | www.26299b.com | vncseojs.com | 3522s.cc | www.9068gg.com | www.11vn777.com | www.371s.cc | 80060202.com | 3059.com | www.836666e.com | www.456.tm | www.594611.com | 001122333.com | 2505am.com | www.pj00880.com | www.12455u.com | ms38648mm.cc | 65365.com | www.w88w118.com | www.40288w.com | www.808482.com | 9506z.com | www.81866n.com | www.668cp44.com | www.00840x.com | 3938oo.com | 66876j.com | www.03543.com | www.85267.com | 111b9.com | 47fhyl.com | www.b0008.com | www.0343u.com | www.234259.com | 54249955.com | www.25288s.com | www.087k.com | www.606255.com | 66648c.com | www.55268ss.com | www.6868.tw | www.289917.com | gg40033.com | www.2078c.com | www.hr1555.com | 6002aa.com | 32126k.net | www.41610.com | www.50788r.com | 1649.com | d88.com | www.4078f.com | www.711853.com | 2997776.com | www.558077.com | www.966735.com | hb61788.com | zhcp05.com | www.288988b.com | www.912063.com | 5906gg.com | www.8882567.com | www.xh289.com | 78666c.com | 9995.cc | www.7334d.com | www.676477.com | pj00ee.com | www.660077.com | www.4189b.com | 5855uu.com | www.hg7288.com | www.068633.com | 272o.net | 3424o.com | www.33678pp.com | www.33598o.com | 2381qq.com | www.xpj2090.com | www.364616.com | 28288aa.com | www.5049v.com | www.755860.com | 5219d.com | www.k2678.com | www.915655.com | 4255dd.com | www.pj79777.com | www.hr5888.com | o40033.com | www.bmw9968.com | www.cc6769.com | 40033ooo.com | www.17035.com | www.xinyc4.com | 04666p.com | www.hwx688.com | www.792587.com | 2138001.com | www.cp66611.com | www.435050.com | iiii19927.com | www.5981q.com | www.012288.com | 9995m.cc | www.490802.com | 060939.com | www.1019994.com | www.9646l.com | 1675ee.com | www.amdc0005.com | www.w984.com | 8159eee.cc | www.twcp55.com | www.178591.com | j2649.com | www.773bbb.com | 0860x.com | www.38778d.com | www.8499w.com | 32666e.com | www.9c123.com | www.91233o.com | 1168t.com | www.2418002.com | 898v.com | www.67894.com | www.612210.com | 44488d.com | www.pj55715.com | YHvip.vip | www.122hg.com | www.843933.com | tz397.com | www.07679v.com | 61326600.com | www.gf11888.com | www.985026.com | dz576.com | www.468860.com | 32355gg.com | www.5675858.com | www.548611.com | 9149p.com | www.6613644.com | TY5509.com | www.hg98097.com | 099568.com | www.88837v.com | www.971261.com | feicai0596.com | www.4833042.com | 11422.vip | www.rycp048.com | yh777.com | www.09569i.com | www.853199.com | 3178xx.com | www.96386g.com | 4556b.com | www.69567h.com |