简体   繁体   English

Unity 3D:使用 Photon 的多人游戏的 2D 物理

[英]Unity 3D: 2D physics for a multiplayer game using Photon

I am currently struggling to figure out how to push a cart.我目前正在努力弄清楚如何推车。 To help you imagine what I'm trying to achieve, I'll try to give my best description.为了帮助您想象我想要达到的目标,我会尽力给出最好的描述。 Imagine you have 3 friends and a rectangle.想象一下,你有 3 个朋友和一个矩形。 Each of your friends including you grabbed a rectangle by the corner and you want to move it to the specified position.你的每个朋友,包括你,都在角落里抓了一个矩形,你想把它移动到指定的位置。 You are glued to this corner meaning you move with a rectangle as it's pushed or pulled.你被粘在这个角落意味着你在推动或拉动矩形时移动它。 You can push it in the same direction as your friends or opposite, the forces are applied by each of you into that corner (if 2 of you were to push up and 2 of you down, the force is zero, if 4 of you push up, its 4 times as strong as if one would push it).您可以将其推向与您的朋友相同或相反的方向,力由你们每个人施加到那个角落(如果你们中的 2 个向上推,而你们中的 2 个向下推,则力为零,如果你们中有 4 个推向上,它的强度是推动它的 4 倍)。 So my question is, how do I make the physics for the players (friends) and a cart (rectangle)?所以我的问题是,我如何为玩家(朋友)和购物车(矩形)制作物理? The game is 2d and you have a view from the top, similar to the "Overcooked" game.游戏是 2d 的,你可以从顶部看到,类似于“Overcooked”游戏。 A concept without an actual script is also fine for me, cause it's hard for me to even think of how I would do it.没有实际脚本的概念对我来说也很好,因为我什至很难想到我会怎么做。

One approach would be to calculate the forces for each player (as a vector2 or vector3) and then apply those to your cart object.一种方法是计算每个玩家的力(作为向量 2 或向量 3),然后将它们应用于您的购物车对象。 the physics engine will handle calculating which way the cart should move on its own.物理引擎将处理计算推车应自行移动的方式。

You can then attach the player objects to the cart, and control their movement that way.然后,您可以将玩家对象附加到购物车,并以这种方式控制他们的移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM