Line 937:
Line 937:
----
----
−
===== setVelocityFunc =====
+
===== setVelocityFunc =====
+
<!-- code start-->
+
<pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">self = physics.Body:setVelocityFunc(func)
+
</pre><!-- code end-->
+
<!-- table start -->
−
<!-- code start-->
+
{| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable"
−
<pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">
+
|-
−
self = physics.Body:setVelocityFunc(func)
+
! Parameter
−
</pre><!-- code end-->
+
! Type
−
+
! Description <!-- header row end -->
−
−
<!-- table start -->
−
{| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable"
−
<!-- header row start -->
−
! Parameter !! Type !! Description
−
<!-- header row end -->
|-
|-
−
| self
+
| self
−
| '''in''' physics.Body
+
| '''in''' physics.Body
−
| The input Body
+
| The input Body
|-
|-
−
| func
+
| func
−
| '''in''' function(body, grav, damping, dt)
+
| '''in''' function(body, grav, damping, dt)
−
| A callback function that updates the velocity of the Body on each time step
+
| A callback function that updates the velocity of the Body on each time step
|-
|-
−
| self
+
| self
−
| '''out''' physics.Body
+
| '''out''' physics.Body
−
| The input Body is returned as the output
+
| The input Body is returned as the output
−
|}<!-- table end -->
+
|}
+
<!-- table end -->
+
<br> Sets the velocity function of the body. The velocity function must be a function that accepts a Body, a gravity [[#vector|vector]], a numeric damping factor, and a time step value. The function should call body:updateVelocity to adjust the velocity of the body.
−
<br/>
+
Returns the Body.
−
Sets the velocity function of the body. The velocity function must be a function that accepts a Body, a gravity [[#vector|vector]], a numeric damping factor, and a time step value. The function should call body:updateVelocity to adjust the velocity of the body.
−
Returns the Body.
{| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#ddffdd;"
{| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#ddffdd;"
|-
|-
−
| <span style="color:#00AA00">'''TIP''':</span> '''Example'''<hr>
+
|
−
|-
+
<span style="color:#00AA00">'''TIP''':</span> '''Example'''
−
<div style="white-space: pre">
+
<br>function sampleVelocityFunc(body, gravity, damping, dt)<br>local pos = body:pos()<br>local sqdist = pos:lengthsq()<br>local g = pos:mult(-GravityStrength / (sqdist * math.sqrt(sqdist)))<br>body:updateVelocity(g, damping, dt)<br>end
+
body:setVelocityFunc(sampleVelocityFunc)<br><br>
−
<!-- code start-->
+
----
−
<pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">
−
function sampleVelocityFunc(body, gravity, damping, dt)
−
local pos = body:pos()
−
local sqdist = pos:lengthsq()
−
local g = pos:mult(-GravityStrength / (sqdist * math.sqrt(sqdist)))
−
body:updateVelocity(g, damping, dt)
−
end
−
body:setVelocityFunc(sampleVelocityFunc)
+
|}
−
</pre><!-- code end-->
+
<br>
−
</div>
+
Introduced in platform.apiLevel = '2.0'
−
|}
−
<br/>
−
Introduced in platform.apiLevel = '2.0'
+
----
−
----
===== setVLimit =====
===== setVLimit =====