Physics Bodies 物理機構

Bodies機構

The physics world is based on the interactions of rigid bodies. These physical bodies can be bound to Corona display objects in a one-to-one relationship, and Corona will automatically handle all position updates and other synchronization tasks.
物理世界是基於剛體的相互作用。這些物理機構可以綁定Corona 顯示對象在一比一的關係,和Corona 會自動處理所有位置更新和其他同步任務。


In fact, our goal is that you should be able to consider the physical bodies as literally part of the visible display objects. Therefore, the body constructor physics.addBody does not return a new object, but instead “extends” an existing display object with physical properties.
事實上,我們的目標是,你應該可以考慮物理機構,因為從字面上的一部分,可見顯示對象。因此,身體構造 physics.addBody不會返回一個新的對象,而是“延伸“一現有的顯示對象的物理特性。


Therefore, standard object read/write attributes like x, y and rotation should continue to work normally on a physical body, although if the bodyType is “dynamic”, the physics engine may “fight back” against your attempts to move the object manually, since the target object will be under the constant effect of gravity and other forces.
因此,標準對象的讀 /寫屬性,如X,Y和旋轉應該繼續正常工作在物理機構上,但如果在bodyType是“動態“的,物理引擎可能“抵抗“針對您嘗試手動移動對象,由於目標對象將是重力和其他力量的常數影響下。


The “DragPlatforms” sample code shows one method for changing body types to “kinematic” during dragging, which temporarily removes them from the influence of external forces. 
在“DragPlatforms“示例代碼演示了一種方法改變身體類型為“運動“在拖動時,這暫時移除它們從外部勢力的影響。


In contrast, the "DebugDraw" sample shows a method for dragging objects using "touch joints" that does not remove them from external forces. 
與此相反,“DebugDraw“示例顯示了一個方法拖動對象使用“觸摸關節“,這並不能從外部力量消除他們。


The second method is probably more useful in physics-based games, but you can compare the two examples to see the difference between "kinematic" and "dynamic" object behavior.
第二種方法可能更有益的物理為基礎的比賽,但是你可以比較兩個例子,看到的區別““運動“和”動態“對象的行為。


A display object that has physical properties can be deleted in the normal way, using object:removeSelf(). It will be automatically removed from both the visible screen and the physical simulation. 
一個顯示對象,具有物理屬性可以以正常方式刪除,使用 object:removeSelf()。它會被自動刪除無論從可視屏幕和物理模擬。


Note: You cannot remove the Physics properties of an object -- you can only remove the entire object.
注意:您不能刪除一個對象的物理特性- 您只能刪除整個對象。


Simple body construction簡單的機身結構


physics.addBody

This allows you to turn any Corona display object into a simulated physical object with one line of code, including the assignment of physical properties.
這使您可以將任何Corona 顯示對象 成模擬的物理對象一行代碼,包括分配的物理特性。


Physical bodies have three main physical properties:
物理機構有三個主要的物理性能:


*density is multiplied by the area of the body’s shape to determine its mass. 
This parameter is based on a standard value of 1.0 for water, so materials that are lighter than water (such as wood) have a density below 1.0, and heavier materials (such as stone) have a density greater than 1.0. 
密度乘以面積身體的形狀來確定它的質量。
此參數是基於一個標準值1.0的水,所以材料都輕於水(如木材)的密度小於 1.0,和重的材料(如石頭)有密度大於1.0。


However, feel free to set density values to whatever feels right for your game, since overall object behavior will also depend on your gravity and pixels-to-meter scale settings (see previous section). The default value is 1.0.
但是,隨意設置密度值的任何感覺對你的遊戲,因為總體目標的行為也將取決於您的重力和像素到米比例設置(見上一節)。默認值是1.0。


*friction may be any non-negative value; a value of 0 means no friction and 1.0 means fairly strong friction. The default value is 0.3.
摩擦可以是任何非負值,一個值為 0意味著沒有摩擦,1.0表示比較強烈的摩擦。默認值是0.3。


*bounce is the Box2d property known internally as “restitution”, and determines how much of an object’s velocity is returned after a collision. Values greater than 0.3 are fairly “bouncy”, and an object with a bounce value of 1.0 will rebound forever (i.e., if dropped to the ground, it will bounce back up to roughly the height from which it was dropped). Bounce values higher than 1.0 are valid, but will cause strange behavior: objects will literally gain velocity with each collision until they fly off into space. The default value is 0.2, which is slightly bouncy.
彈性是Box2D的屬性著名國內的“恢復原狀“,並確定有多少對象的速度發生碰撞後返回。值大於 0.3是相當“有彈性“,以及一個對象,具有反彈值1.0將反彈到永遠(即,如果掉在了地上,它還會彈回來了約有的高度,從它被丟棄)。彈跳值高於 1.0是有效的,但會導致奇怪的行為:對象將獲得字面上與每個碰撞速度飛了過去,直到他們進入太空。默認值是0.2,這是稍微有彈性。


Note:
You may find that an object with a bounce set to exactly 1.0 will rebound somewhat higher than its original height, due to numerical approximations in Box2D. Bounce values slightly below 1.0, possibly combined with some linear damping, may be used for a closer simulation of "same height" behavior over short periods of time. Over long periods of time, it may be difficult to avoid runaway or decaying bounce.
注意:
您可能會發現一個對象,具有反彈設置為1.0將反彈正好略高於原來的高度,由於在Box2D數值逼近。彈跳值稍低於 1.0,可能結合一些線性阻尼,可用於模擬一個接近“同一高度“行為在短時間內的時間。在很長一段時間,可能難以避免失控或腐爛的反彈。


Default (rectangular) bodies默認(矩形)機構


By default, this constructor assumes that the physical object is rectangular, with collision boundaries that automatically snap to the edges of the associated image or vector object. This works well for crates, platforms, large ground bodies, and other simple rectangular sprites. All parameters in the table are optional, and all default to reasonable values if not provided.
默認情況下,這個假設的物理構造對象是矩形,碰撞的界限,自動捕捉到的相關圖像邊緣或矢量對象。這很適合箱子,平台,大型地面機構以及其他簡單的矩形精靈。表中的所有參數都是可選的,默認為所有合理的值,如果沒有提供。
--------------------------
local crate = display.newImage( "crate.png", 100, 200 )
physics.addBody( crate, { density = 1.0, friction = 0.3, bounce = 0.2 } )
--------------------------
Note that the table of physical attributes can be declared externally and then used multiple times:
注意該表的物理屬性可以被聲明為外部,然後多次使用:
---------------------------
local crate1 = display.newImage( "crate.png", 100, 200 )
local crate2 = display.newImage( "crate.png", 180, 280 )
 
local crateMaterial = { density = 1.0, friction = 0.3, bounce = 0.2 }
 
physics.addBody( crate1, crateMaterial )
physics.addBody( crate2, crateMaterial )
-------------------------------------
Also note that this default constructor assumes that your physics object has the same rectangular boundaries as your display object. This is very convenient in many cases, but in other cases may not be what you want. For example, a vector line drawn diagonally using display.newLine() is actually rendered as a rectangular object, since it creates a rectangular area of OpenGL texture (which would be mostly transparent, in this case).
另外請注意,此默認構造假設你的物理對象具有相同的矩形邊界為您顯示對象。這是非常方便,在許多情況下,但在其他情況下可能不是你想要的。例如,使用矢量線繪製對角display.newLine()實際上是呈現為一個矩形對象,因為它創建一個矩形區域的OpenGL紋理(這將是通透,在這種情況下)。


If you do not want your physics body to match this bounding rectangle, you should define more specific shape data using either the circular radius property or the array of polygon coordinates discussed below.
如果你不想你的物理身體,以配合這個邊界矩形,你應該更具體的定義形狀數據要使用什麼樣的圓形半徑屬性或多邊形坐標陣列下面討論。


When in doubt, you can use physics.setDrawMode() to get a "behind the scenes" view of what the physics engine is actually doing, including the collision boundaries for your physics bodies.
如有疑問,您可以使用physics.setDrawMode()來得到一個“幕後“的觀點是什麼物理引擎實際上是在做,包括你的物理碰撞分界機構。


Circular bodies圓體

Circular bodies require an additional radius parameter. This works well for balls, rocks, and other objects that can be treated as perfectly round when calculating collisions. If the visible sprite is round but irregular (say, a boulder or an egg), you may wish to set this radius slightly smaller than the physical image size.
圓形的身體需要額外的半徑參數。這很適合球,岩石和其他對象,可以被視為是完美的圓形,當計算碰撞。如果可見精靈是圓的,而是不規則的(例如,一巨石或雞蛋),您可能希望設置這個半徑略小於物理圖像的大小。


Note that there is no such thing as a non-circular oval in Box2D collision geometry, since circular bodies exist as a special case. To make an oval body, you would instead lay out a series of specific boundary points to outline the shape as a polygon (see below).
請注意有沒有這樣的東西非圓形橢圓形幾何在Box2D碰撞,因為圓形機構存在,作為一個特例。為了使一個橢圓形的身體,你反而會制定出一系列具體的邊界點的輪廓形狀為多邊形(見下文)。
-----------------------
local ball = display.newImage( "ball.png", 100, 200 )
physics.addBody( ball, { density = 1.0, friction = 0.3, bounce = 0.2, radius = 25 } )
------------------------


Polygon bodies多邊形機構

General polygonal bodies that don’t fall into the above two special cases are generated with a “shape” parameter, which is used to pass a Lua table of (x,y) coordinate points that outline the collision boundaries. These coordinates are specified relative to the display object: by default, Corona sets the origin of a display object at the center of the corresponding image file (or vector object).
一般多邊形機構不屬於上述兩種特殊情況下產生了“形“參數,它是用來傳遞一個 Lua表(的x,y)坐標點,勾勒出碰撞邊界。這些坐標指定相對於顯示對象:默認情況下,Corona 設置顯示對象的起源中心在相應的圖像文件(或矢量對象)。


For example, to define a rectangular shape 20 pixels high and 40 pixels wide, with its origin at its center, the following shape definition would be used:
例如,要定義一個長方形高20像素和40像素寬,其原產地為中心,下面的形狀定義將用於:
----------------------
squareShape = { -20,-10, 20,-10, 20,10, -20,10 }
-----------------------
The maximum number of points (and therefore edges) allowed per collision shape is eight. Once defined, a shape definition can be re-used multiple times.
最高點數(因此邊緣)允許每個碰撞型狀是八。一旦定義,形狀定義可以重複使用多次。


Note that these polygon coordinates must be defined in clockwise order, and the resulting shape must be convex-only. Coordinate sets that violate these two rules may appear to work, but their objects will behave oddly in collisions: for example, they may become stuck to other objects. (Concave physical objects must be assembled from multiple elements attached to the same body; see "Complex body construction" below.)
請注意,這些多邊形的坐標必須定義在順時針順序,以及由此產生的形狀必須是凸形。坐標集違反規則可能會出現這兩個工作,但他們的行為很古怪的物體碰撞:例如,他們可能成為堅持到其他物體。 (凹物理對象必須從多個元素進行組裝連接到相同的身體,見“複合體結構“一節。)


Here are two valid examples:
這裡有兩個有效的例子:
--------------------
local triangle = display.newImage("triangle.png")
triangle.x = 200
triangle.y = 150
triangleShape = { 0,-35, 37,30, -37,30 }
 
physics.addBody( triangle, { density=1.6, friction=0.5, bounce=0.2, shape=triangleShape } )


local pentagon = display.newImage("pentagon.png")
pentagon.x = 200
pentagon.y = 50
pentagonShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }
 
physics.addBody( pentagon, { density=3.0, friction=0.8, bounce=0.3, shape=pentagonShape } )
----------------------------
For examples of polygonal body specifications, see “ShapeTumbler” and the bumper objects in “SimplePool”.
舉例來說多邊形體規格,請參閱“ShapeTumbler“和緩衝器槓對象“SimplePool“。


bodyType ConstructorbodyType構造

Here are two ways to specify the bodyType when adding a Physics body.
這裡有兩種方法可以指定bodyType當添加一個物理的身體。
-------------------------------
physics.addBody( triangle, "static", { density=1.6, friction=0.5, bounce=0.2, shape=triangleShape } )
--------------------------------
Alternatively, you can construct the body and then set its type attribute:
或者,您可以構造體,然後將其類型屬性:
-------------------------
physics.addBody( triangle, { density=1.6, friction=0.5, bounce=0.2, shape=triangleShape } )
triangle.bodyType = "static"
---------------------------
Possible bodyTypes are “static”, “dynamic” and “kinematic”, and the default type is “dynamic” if no value is specified.
可能bodyTypes是“靜態“,“動態”和“運動“,而默認類型是“動態“如果沒有指定值。


In general, you can allow moving objects to default to “dynamic”, and specify “static” for objects (like walls or the ground) that shouldn’t move or fall under gravity.
一般情況下,可以允許移動物體默認為“動態”,並指定“靜態“的對象(如牆壁或地面),不應移動或在重力作用下。


Complex body construction複雜的身體結構


The above examples assume a body with only one element. However, it is also possible to construct a body from multiple elements. In this context, each body element is specified as a separate polygon shape with its own physical properties.
上述例子假設一個機構,只有一個元素。不過,也有可能建立一個身體從多個元素。在這種情況下,每一個 body元素被指定為一個單獨的多邊形的形狀,其自身的物理特性。


For example, to model a pencil, you would probably want to define the eraser end as a separate body element with a much higher “bounce” value than the rest of the pencil.
例如,一支鉛筆的模型,您可能要定義橡皮擦結束作為一個單獨的主體元素以更高的“反彈“的價值比其他的鉛筆。


Also, since collision polygons in Box2D must be convex, any game object with a concave shape must be constructed by appending multiple body elements. For example, to model a car, you would use a body with two or more body elements, since the shape of a car includes concave angles, such as the angle where the windshield meets the hood of the car.
此外,由於碰撞,必須在Box2D多邊形凸的,任何遊戲對象凹形狀的施工必須由多個機構追加元素。例如,模擬一個車,你會用身體與兩個或更多的體元素,因為汽車的形狀,包括凹角,角的地方,如符合罩在擋風玻璃上的汽車。


The constructor for a complex body is the same as the simple polygon body constructor, except with more than one body element listed:
該構造一個複雜的身體是一樣的身體構造簡單的多邊形,除非列出的一個以上身體元素:

physics.addBody( displayObject, [bodyType,] bodyElement1, [bodyElement2, ...] )

Each body element may have its own physical properties, along with a shape definition for its collision boundaries. For example:
每一個機構元素可能有自己的物理性能,以及一個形狀定義的碰撞邊界。例如:
---------------------------------------------------
local car = display.newImage("big_red_car.png")
roofShape = { -20,-10, 20,-10, 20,10, -20,10 }
hoodShape = { 0,-35, 37,30, -37,30 }
trunkShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }
  
physics.addBody( car, "dynamic",
  { density=3.0, friction=0.5, bounce=0.2, shape=roofShape },
  { density=6.0, friction=0.6, bounce=0.4, shape=hoodShape },
  { density=4.0, friction=0.5, bounce=0.4, shape=trunkShape }
)
------------------------------------------------------
(These shape definitions are for example only, and probably would not make a very good car shape.)
(這些形狀的定義只是舉例,可能不會使一個很好的汽車形狀。)


As in the simpler cases, the bodyType attribute is optional and will default to “dynamic” if not specified.
正如在簡單的情況下,bodyType屬性是可選的,默認為“動態“如果沒有指定。


Sensors感應器


Any body (or element of a multi-element body) can be turned into a “sensor”. Sensors do not physically interact with other bodies, but produce collision events when other bodies pass through them. For example, the pockets on a pool table might be implemented as sensors.
任何機構(或元素的多元素體)可變成了“感應器“。不物理感應器與其他機構的互動,但產生的碰撞事件時,其他機構通過它們。例如,口袋台球桌可能將實施的感應器。


Because the simplest Corona body constructors are based on visible display objects, the easiest way to implement an invisible sensor region is to create a display object and then make it invisible:
由於身體構造最簡單的Corona 基於可見的顯示對象,最簡單的方法來實現一種無形的感應器區域要創建一個顯示對象,然後使之不可見:
------------------------
local rect = display.newRect( 50, 50, 100, 100 )
rect:setFillColor( 255, 255, 255, 100 )
rect.isVisible = false  -- optional
physics.addBody( rect, { isSensor = true } )
--------------------------
The visible object can be used for game debugging, and then the isVisible property can be set to false once debugging is complete. In the above example, the initial display object is a translucent vector rectangle using the Corona drawing API.
可見的對象可用於遊戲調試,然後 IsVisible屬性可以設置為 false,一旦調試完成。在上面的例子中,初始顯示對象是一個半透明的矩形使用Corona 矢量繪圖 API。


Destroying bodies銷毀機構

Physics bodies can be destroyed like any other display objects:
物理機構,可以像任何其他顯示銷毀對象:
-------------------------
myBody:removeSelf()
-- or --
myBody.parent:remove( myBody )
------------------------------
The first method above is recommended for simplicity, and is the same syntax used to destroy physics joints (which do not have parents, since they are invisible and not part of the display hierarchy).
第一種方法為簡單起見,上述建議,是相同的語法用來摧毀物理關節(其中沒有父母,因為他們是無形的,而不是一部分的顯示層次結構)。


When you destroy bodies or joints, Corona will automatically handle the process of holding onto the corresponding Box2D objects until the end of the current physics world step, and then safely dispose of them.
當你摧毀機構或接縫,Corona 處理過程中會自動持有到相應 Box2D的對象,直到結束當前的物理世界的一步,然後安全地處置它們。


Note:
While Box2D objects will be safely retained until the end of the current world step, their Lua references will be deleted immediately. Therefore, be careful not to accidentally delete the same Lua object more than once. This situation could occur when deleting objects involved in collisions, which can potentially have many event phases before the collision is fully resolved. The solution is simple:
注意:
雖然 Box2D的對象將被安全地保留到最後是當今世界的一步,他們的Lua的言論將被立即刪除。因此,要小心不要意外刪除相同的Lua對象不止一次。這種情況可能發生在刪除對象涉及碰撞,最終也可能有許多事件相碰撞前完全解決。解決的辦法很簡單:
-----------------------
local function onCollision( self, event )
        if ( event.phase == "began" ) then
                 -- Check if body still exists before removing!
                if ( crate1 ) then
                        crate1:removeSelf()
                        crate1 = nil
                end
 
        end
end
---------------------

Body properties
Body屬性
Many of the native Box2D setter/getter methods have been reduced to simpler dot properties on the display object. The following examples assume that a body myBody has been created using one of the above constructor methods.
許多本地Box2D的setter / getter方法​​已減少到​​簡單點的屬性上顯示對象。下面的例子假設,一個物體 myBody已創建使用一個以上的構造方法。
-----------------
body.isAwake
-------------------
A boolean for the current awake state. 
當前清醒狀態是一個布爾值。


By default, all bodies automatically “go to sleep” when nothing interacts with them for a couple of seconds, and then they stop being simulated until something (e.g., a collision) wakes them up. This property can either fetch their current state or forcibly wake them up.
默認情況下,所有機構自動“去睡覺“沒事的時候與他們相互作用的幾個秒,然後,他們不再是模擬碰撞,直到它們喚醒。這個屬性可以獲取其當前狀態或強行叫醒他們。
----------------
myBody.isAwake = true
local state = myBody.isAwake
--------------------

body.isBodyActive
A boolean for the current active state. Inactive bodies are not destroyed, but they are removed from the simulation and cease to interact with other bodies.
前活動狀態是一個布爾值。不活躍的身體不被破壞,但他們將被刪除從模擬和終止和其它的機構互動
-------------------------
myBody.isBodyActive = true
local state = myBody.isBodyActive
---------------------------

body.isBullet

A boolean for whether the body should be treated as a “bullet”. 
該機構是否應被視為一個“砲彈”。是一個布爾值


Bullets are subject to continuous collision detection, rather than periodic collision detection at world timesteps. 
砲彈都受到連續碰撞檢測,而不是在世界時間步驟週期性 碰撞檢測 。


This is more computationally expensive, but it prevents fast-moving objects from passing through solid barriers. The default is false.
這是更昂貴的計算,但它可以防止快速移動的物體 穿過 堅實屏障。默認為 false。


body.isSensor

A (write-only) boolean property that sets an internal "isSensor" property across all elements in the body. 
一個(只寫)布爾屬性,設置了一個內部“isSensor“屬性跨越在體內的所有元素。


A sensor passes through other objects rather than bouncing off them, but still fires some collision events (for example, the table pockets in the "SimplePool" sample code are sensors). 
經過一個感應器等對象,而不是他們的反彈,但仍有些碰撞火災事件(例如,表口袋中的“SimplePool“示例代碼的感應器)。


Because this body property acts across all body elements, it unconditionally overrides any "isSensor" settings on the elements themselves.


由於這個機構屬性的動作跨越所有身體的元素,它無條件地覆蓋任何“isSensor“設置的元素本身。
------------------
myBody.isSensor = true
-------------------

body.isSleepingAllowed

A boolean for whether the body is ever allowed to go to sleep. 
該機構是否任何時候都可以去睡覺是一個布爾值。
true 表示沒有碰撞時body is sleep.


Keeping bodies awake has a larger overhead, and is often not required, because collisions with other bodies will automatically wake them up. 
保持清醒的機構有較大的開銷,通常不是必需的,因為與其他機構的碰撞會自動叫醒他們。


However, forcing awakeness is useful in cases such as the tilt-gravity case (since sleeping bodies do not respond to changes in global gravity). The default is true.
然而,迫使覺醒是有用的情況下,如傾斜重力情況下(因為睡機構不響應全球變化的重力)。默認為 true。


-------------------------
myBody.isSleepingAllowed = true
local state = myBody.isSleepingAllowed
-------------------------

body.isFixedRotation

A boolean for whether the rotation of the body should be locked, even if the body is under load or subjected to off-center forces. The default is false.
是否旋轉的機構應被鎖定這是一個布爾,即使身體負荷或正在遭受偏離中心的力量。默認為 false。
---------------------
myBody.isFixedRotation = true
local state = myBody.isFixedRotation
-------------------------

body.angularVelocity

The numerical value of the current angular (rotational) velocity, in degrees per second.
當前角度(旋轉)的速度數值,以度每秒。
---------------------------
myBody.angularVelocity = 50
local v = myBody.angularVelocity
----------------------------

body.linearDamping

The numerical value for how much the body's linear motion is damped. The default is zero.
有多少身體的直線運動數值被抑制。默認是零。
------------------------
myBody.linearDamping = 5
local d = myBody.linearDamping
------------------------

body.angularDamping

The numerical value for how much the body's rotation should be damped. The default is zero.
有多少身體的轉動數值為應阻尼。默認是零。
------------------------
myBody.angularDamping = 5
local d = myBody.angularDamping
------------------------

body.bodyType

A string value for the type of physical body being simulated. Possible values are "static", "dynamic" and "kinematic".
一個字符串值類型的身體被模擬。可能的值是“靜態“,“動態”和“運動“。


*static bodies don't move, and don't interact with each other; examples of static objects would include the ground, or the walls of a pinball machine.
*靜態機構不動,並且不互相影響;例子靜態對象將包括地面,牆壁或一個彈球機。


*dynamic bodies are affected by gravity and collisions with the other body types.
*動態物體受重力和碰撞與其他機構的類型。


*kinematic objects are affected by forces but not by gravity, so you should generally set draggable objects to “kinematic”, at least for the duration of the drag event.
The default body type is "dynamic".
*運動物體受力,但不是由重力,所以你應該設置可拖動對象一般為“運動“,至少在此期間的拖動事件。
默認的身體類型是“動態“。
------------------------
myBody.bodyType = "kinematic"
local currentType = myBody.bodyType
-------------------------

Body methods

The following examples assume that a body myBody has been created using one of the above constructor methods.
下面的例子假設,一個物體 myBody已創建使用一個以上的構造方法。

body:setLinearVelocity

A function that accepts x,y components for the body's linear velocity, in pixels per second.
一個函數接受的x,y分量對身體的線性速度,以像素每秒。
---------------------
myBody:setLinearVelocity( 2, 4 )
-----------------------------

body:getLinearVelocity

A function that returns x,y components for the body's linear velocity, in pixels per second.
一個函數,返回x,y分量對身體的線性速度,以像素每秒。
vx, vy = myBody:getLinearVelocity()
-------------------------------------

body:applyForce


A function that accepts x,y components of a linear force, applied at a given point with x,y world coordinates. 
一個函數接受的x,y分量的線性力,適用於在某一時間點上的x,y世界坐標。


If the target point is the body's center of mass, it will tend to push the body in a straight line; if the target is offset from the body's center of mass, the body will spin about its center of mass.
如果目標點是人體的質心的時候,會推動身體在一條直線上,如果目標是從身體失調的質心,身體會旋轉約其質心。


For symmetrical objects, the center of mass and the center of the object will have the same position: (object.x, object.y). Also note that the amount of force may need to be fairly high to move heavy objects.
對於對稱物體,該中心的質量和中心的對象將具有相同的 position : (object.x,object.y)。還要注意的是力的數值可能需要相當高的移動重物。
-------------------------------------
myBody:applyForce( 500, 2000, myBody.x, myBody.y )
------------------------------------

body:applyTorque

A function that accepts a numerical value for applied rotational force. The body will rotate about its center of mass.
一個函數接受一個數值為應用旋轉力。該機構將繞其質心。
-------------------------
myBody:applyTorque( 100 )
--------------------------

body:applyLinearImpulse

Like applyForce, except that an impulse is a single, momentary jolt.
applyForce一樣,除了一衝力是一個單一的,瞬間的震動。
-------------------------------
myBody:applyLinearImpulse( 600, 200, myBody.x, myBody.y )
----------------------------

body:applyAngularImpulse

Like applyTorque, except that an angular impulse is a single, momentary jolt.
applyTorque一樣,除了一個角衝力是一個單一的,瞬間震動。
------------------
myBody:applyAngularImpulse( 100 )
---------------------


Force vs. Impulse?
力 vs 衝力?

A common question is the difference between applying "force" and "impulse" to a body. 
一個常見的問題是區別應用“力”和“衝力“於一體。

The difference is that an impulse is meant to simulate an immediate "kick" to the body, but force (and torque) is something exerted over time. 
所不同的是,一個衝力是為了模擬一個即時的“踢“的身體,但力(和扭力)施加的東西隨著時間的推移。

Therefore, to get a realistic force simulation, you should reapply the force on every frame, perhaps for several seconds, or as long as you want the force to continue. You can use an "enterFrame" event for this purpose.
因此,要獲得一個模擬現實的力量,你應該重新申請每幀上的力,也許是幾秒鐘,或者只要你想要的力量繼續下去。你可以使用“enterFrame“事件作此用途。


body:resetMassData

If the default mass data for the body has been overridden (TBD), this function resets it to the mass calculated from the shapes.
如果默認身體的質量數據已被重寫(TBD),這個函數並將依其出形狀的重算質量。
--------------
myBody:resetMassData()
--------------




arrow
arrow
    全站熱搜

    createps 發表在 痞客邦 留言(0) 人氣()