wiki.sine.space | sinespace

Difference between revisions of "Scripting/SJointMotor"

From wiki.sine.space
Jump to: navigation, search
Line 35: Line 35:
 
=Properties=
 
=Properties=
  
{{ScriptFunction|float|TargetVelocity|{ get;set; }|The motor will apply a force up to force to achieve targetVelocity.|5=<pre>MotorTargetVelocity = Space.Host.ExecutingObject.HingeJoint.Motor.TargetVelocity</pre>|6=<pre></pre>}}
+
{{ScriptFunction|float|TargetVelocity|{ get;set; }|The motor will apply a force up to force to achieve targetVelocity.|5=<pre>MotorTargetVelocity = Space.Host.ExecutingObject.HingeJoint.Motor.TargetVelocity</pre>|6=<pre>--the below script will make a slider change a Hinge Joint Motor TargetVelocity property
 +
--[Add "theslider" and "thehingejoint" reference to the Scripting Runtime component]
  
{{ScriptFunction|float|Force|{ get;set; }|The motor will apply a force. |5=<pre>MotorForce= Space.Host.ExecutingObject.HingeJoint.Motor.Force </pre>|6=<pre></pre>}}
+
slider = Space.Host.GetReference("theslider").UISlider
 +
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint
  
{{ScriptFunction|bool|FreeSpin|{ get;set; }|If freeSpin is enabled the motor will only accelerate but never slow down.|5=<pre>MotorFreeSpin = Space.Host.ExecutingObject.HingeJoint.Motor.FreeSpin</pre>|6=<pre></pre>}}
+
 
 +
OVC = function()
 +
motor = hingejoint.Motor
 +
motor.TargetVelocity = (slider.Value * 10.0) -- from 0.0 to 10.0
 +
hingejoint.Motor = motor
 +
end
 +
 
 +
slider.OnValueChanged(OVC)</pre>}}
 +
 
 +
{{ScriptFunction|float|Force|{ get;set; }|The motor will apply a force. |5=<pre>MotorForce= Space.Host.ExecutingObject.HingeJoint.Motor.Force </pre>|6=<pre>--the below script will make a slider change a Hinge Joint Motor Force property
 +
--[Add "theslider" and "thehingejoint" reference to the Scripting Runtime component]
 +
 
 +
slider = Space.Host.GetReference("theslider").UISlider
 +
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint
 +
 
 +
 
 +
OVC = function()
 +
motor = hingejoint.Motor
 +
motor.Force = (slider.Value * 10.0) -- from 0.0 to 10.0
 +
hingejoint.Motor = motor
 +
end
 +
 
 +
slider.OnValueChanged(OVC)</pre>}}
 +
 
 +
{{ScriptFunction|bool|FreeSpin|{ get;set; }|If freeSpin is enabled the motor will only accelerate but never slow down.|5=<pre>MotorFreeSpin = Space.Host.ExecutingObject.HingeJoint.Motor.FreeSpin</pre>|6=<pre>--the below script will toggle Hinge Joint Motor FreeSpin property
 +
--[Add "thehingejoint" reference to the Scripting Runtime component]
 +
 
 +
thisGameObject = Space.Host.ExecutingObject
 +
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint
 +
 
 +
 
 +
function OnClickFunction()
 +
motor = hingejoint.Motor
 +
motor.FreeSpin = not motor.FreeSpin
 +
hingejoint.Motor = motor
 +
end
 +
 
 +
thisGameObject.AddClickable()
 +
thisGameObject.Clickable.OnClick(OnClickFunction)</pre>}}
  
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 14:49, 15 January 2022

Static Public Member Functions

New

SJointMotor New (float targetVelocity, float force, bool freeSpin);

Creates a new SJointMotor with the given targetVelocity, force, freeSpin.

Motor= Space.Host.ExecutingObject.HingeJoint.Motor.New(1,2,true)


--the below script will change all Hinge Joint Motor properties to 0 when clicked
--[Add "thehingejoint" reference to the Scripting Runtime component]
thisObject = Space.Host.ExecutingObject
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


function OnClickFunction() 
motor = hingejoint.Motor
hingejoint.Motor = motor.New(0,0,false)
end

thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)


Public Member Functions

ToString

string ToString ();

Returns this SJointMotor's properties as a string

MotorString = Space.Host.ExecutingObject.HingeJoint.Motor.ToString()


--the below script will make a UI Text element display this GameObjects Hinge Joint Motor properties
--[Add "thetext" and "thehingejoint" reference to the Scripting Runtime component]
thisObject = Space.Host.ExecutingObject
text = Space.Host.GetReference("thetext").UIText
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


function OnUpdateFunction()
motor = hingejoint.Motor
text.Text = motor.ToString()
end


thisObject.OnUpdate(OnUpdateFunction)


Properties

TargetVelocity

float TargetVelocity { get;set; }

The motor will apply a force up to force to achieve targetVelocity.

MotorTargetVelocity = Space.Host.ExecutingObject.HingeJoint.Motor.TargetVelocity


--the below script will make a slider change a Hinge Joint Motor TargetVelocity property
--[Add "theslider" and "thehingejoint" reference to the Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


OVC = function()
motor = hingejoint.Motor
motor.TargetVelocity = (slider.Value * 10.0) -- from 0.0 to 10.0
hingejoint.Motor = motor
end

slider.OnValueChanged(OVC)

Force

float Force { get;set; }

The motor will apply a force.

MotorForce= Space.Host.ExecutingObject.HingeJoint.Motor.Force 


--the below script will make a slider change a Hinge Joint Motor Force property
--[Add "theslider" and "thehingejoint" reference to the Scripting Runtime component]

slider = Space.Host.GetReference("theslider").UISlider
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


OVC = function()
motor = hingejoint.Motor
motor.Force = (slider.Value * 10.0) -- from 0.0 to 10.0
hingejoint.Motor = motor
end

slider.OnValueChanged(OVC)

FreeSpin

bool FreeSpin { get;set; }

If freeSpin is enabled the motor will only accelerate but never slow down.

MotorFreeSpin = Space.Host.ExecutingObject.HingeJoint.Motor.FreeSpin


--the below script will toggle Hinge Joint Motor FreeSpin property 
--[Add "thehingejoint" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
hingejoint = Space.Host.GetReference("thehingejoint").HingeJoint


function OnClickFunction()
motor = hingejoint.Motor
motor.FreeSpin = not motor.FreeSpin
hingejoint.Motor = motor
end

thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClickFunction)