How to translate smoothly using api?

27 August 2017 09:19
How can I set a smooth translation (eg 5 seconds) using the api?

I am using transform. set_translation () but it's moving the object instantaneously.
I want to translate over a period of time.
27 August 2017 12:12
Have a look at linear_tween().
There are many various ease functions in the Math Module
Animate() in the Time Module might interest you as well.
29 August 2017 18:08
You attach an "elapsed" sensor to the object, then move the object by speed * elapsed with m_trans.move_local in the sensor's callback function.

Here's a code example:
var m_ctl    = require("control");
var m_trans  = require("transform");
var m_scs    = require("scenes");

// Define your movement parameters:

var name_of_my_object = "my_objects_name"; // Fill in the (Blender) name of your object.
var x_speed = 1;                           // Set your desired speed along X axis (0 for no movement in this axis).
var y_speed = -0.5;                        // Set your desired speed along Y axis (0 for no movement in this axis).
var z_speed = 0;                           // Set your desired speed along Z axis (0 for no movement in this axis).

// Set up sensor:

var elapsed_sensor = m_ctl.create_elapsed_sensor();
m_ctl.create_sensor_manifold(m_scs.get_object_by_name(name_of_my_object), "MOVE", m_ctl.CT_CONTINUOUS, [elapsed_sensor], null, move_cb);

// Callback function:

function move_cb (obj, id) {
  var elapsed = m_ctl.get_sensor_value(obj, id, 0);
  m_trans.move_local(obj, x_speed*elapsed, y_speed*elapsed, z_speed*elapsed); 

There is a nice tutorial about this: Basic Manipulations in 3D Space
Please register or log in to leave a reply.