Rotate object and X movement together


#1

@menithal I Still need to find the script commands wiki and other info back. I have a question.

Is it already possible to rotate objects with a command, And the X is rotating with the object. SO you can keep it moving forward on the x Axis.

Red is the X side.
I did need this command years ago.
And i still need this functionality for lot’s of things.
I hope the now have a command for that.


#2

Thats been doable since the start due to the nature of 3D Mathematics, so its applicable for all platforms:

quaternion * vector gives you the rotated_vector.

So if you do

Vec3.multiply(rotation, {x:1, y:0, z:0})

you get the X Axis of the rotation.

Alternatively we already have helper functions to find what the current forward is via the Quat.getFront method. which gets the Forward direction for the current rotation. If you need other directions you have Quat. getRight and Quat.getUp, and you can always negate the vector to get the opposite direction, with Vec3.multiply(vector, -1)

Then you just apply that to the velocity with a multiple of the speed you want to reach

So forexample

target_speed = 0.2;
id = "<insert entity id here>";
properties = Entities.getEntityProperties(id)
// Gets the Front of the entity
var front = Quat.getFront(properties.rotation); 
// set the new velocity
properties.velocity = Vec3.multiply(front, target_speed); 

// Apply that property
Entities.editEntity(id, properties);

Will impulse move the entity forwards for a 20 cm/s its forward axis

Equally the same method is used to spawn things infront of other things, like with my flaregun or hookgun