MotionController Component

From ANVEL Wiki
Jump to: navigation, search
Noun 336.png | Experimental: The Motion Controller Component is an experimental feature in ANVEL 3.5.

Introduction

The MotionController component allows the application of automatic position updates to an object that does not already include physics simulation. Users set up desired velocities and orientations and the component will handle position and rotation updates for the object. The MotionController uses linear interpolation to adjust the speed between the StartVelocity and EndVelocity values, and spherical linear interpolation to set the orientation between the StartOrientation and EndOrientation values. Use the InterpolationDuration to specify the duration of the interpolation, in seconds. If no interpolation is desired, set the InterpolationDuration property value to 0. Once the interpolation is finished, the object will stay moving with the velocity specified in EndVelocity, while utilizing the orientation specified in EndOrientation.

This component is generally intended for use with the PythonScript Component and external API to allow direct object control without requiring a once per simulation tick update.

Properties

Name Type Description
StartVelocity Vector3 The starting velocity (unused if no interpolation is taking place)
EndVelocity Vector3 The ending velocity (or desired velocity if not interpolation is taking place)
StartOrientation Quaternion Starting orientation value to use (ignored if no interpolation will take place
EndOrientation Quaternion The final orientation, after interpolation has been completed
InterpolationDuration double Time, in seconds, to transition between start and end velocities and orientations; if 0, no interpolation will take place
ElapsedTime double Time since last request was made; must reset to 0 after changing velocity or orientation values to restart the interpolation

Usage

Built-In Python Examples

Constant Velocity

The following example uses the MotionController component to move an object with constant velocity. The component is attached to the object, and then the desired velocity property is adjusted. Once the simulation starts, the cube will instantly start moving at a constant velocity of 1m/s in the y direction.

myObject = Anvel.Assets.CreateInstance("Cube (Transparent)", "TestConstantVelocityCube", 0, (1,0,1), (1,0,0,0), (1,1,1), False )
motion = Anvel.World.AddComponent( myObject, Anvel.Enums.ComponentType.MotionController )
Anvel.SetPropertyByName( motion, "EndVelocity", Anvel.Vector3(0, 1, 0) )
Anvel.Simulation.Resume()

Smooth Acceleration

The below example shows smooth acceleration with the MotionController component.

#First, create an object to test with
myObject = Anvel.Assets.CreateInstance("Cube (Transparent)", "TestAccelerationCube", 0, (1,0,1), (1,0,0,0), (1,1,1), False )
#Create the MotionController component on the test object
motion = Anvel.World.AddComponent( myObject, Anvel.Enums.ComponentType.MotionController )

#Configure the MotionController properties to achieve our desired behavior, in this case
#we would like the object to start from a rest, then accelerate to 5 meters per second
#over the course of 10 seconds. 

#The object should start from a rest
Anvel.SetPropertyByName( motion, "StartVelocity", Anvel.Vector3(0, 0, 0) )
#Desired target speed is 5 meters per second in the x direction
Anvel.SetPropertyByName( motion, "EndVelocity", Anvel.Vector3(5, 0, 0) )
#Accelerate to our desired speed over the course of 10 seconds
Anvel.SetPropertyByName( motion, "InterpolationDuration", 10.0 )

Anvel.Simulation.Resume()

Smooth Rotation

This example utilizes the StartOrientation and EndOrientation properties to smoothly rotate the object, while maintaining a constant forward velocity.

myObject = Anvel.Assets.CreateInstance("Cube (Transparent)", "TestRotationCube", 0, (1,0,1), (1,0,0,0), (1,1,1), False )
#Create the MotionController component on the test object
motion = Anvel.World.AddComponent( myObject, Anvel.Enums.ComponentType.MotionController )

#The object should start with our desired velocity
Anvel.SetPropertyByName( motion, "StartVelocity", Anvel.Vector3(3, 0, 0) )
#Utilize a default orientation to face down the x axis
Anvel.SetPropertyByName( motion, "StartOrientation", Anvel.Quaternion(1, 0, 0, 0) )
#Desired target speed is the same as our starting velocity
Anvel.SetPropertyByName( motion, "EndVelocity", Anvel.Vector3(3, 0, 0) )
#Set the desired end orientation to be a 90 degree left turn from our starting rotation
Anvel.SetPropertyByName( motion, "EndOrientation", Anvel.Quaternion(0.70710678118, 0, 0, 0.70710678118) )
#Rotate to our new desired direction over the course of 10 seconds
Anvel.SetPropertyByName( motion, "InterpolationDuration", 10.0 )
#Ensure that VelocityInLocalSpace is true so that the object continues to move with a forward velocity, even
#though the object will be changing direction
Anvel.SetPropertyByName( motion, "VelocityInLocalSpace", True )

#Focus our camera on the world object and start the simulation
Anvel.Views.FocusViewOnObject( myObject )
Anvel.Simulation.Resume()

See Also

Component System