How to prevent the RigidBody to rotate along the axes X and Y, allow only on axis Z?
My code (In it, the body sometimes turns over, and this must be prevented):
var dir = object.transform.look().normalize();
var vel = new Vec4(
dir.x * forward_speed,
dir.y * forward_speed,
dir.z * forward_speed);
body.setLinearVelocity(vel.x, vel.y, vel.z);
body.setAngularVelocity(0,0,rotation_speed);
package arm;
import iron.math.Vec4;
import armory.trait.physics.RigidBody;
import iron.Trait;
// AUTONOMOUS AGENT
class TestAI extends Trait {
#if (!arm_physics)
public function new() {
super();
}
#else
var body:RigidBody;
var move_speed = 30;
var turn_speed = 3;
public function new() {
super();
iron.Scene.active.notifyOnInit(init);
}
function init() {
// get all components
body = object.getTrait(RigidBody);
notifyOnUpdate(update);
}
function update() {
// move (in future change to apply force)
var dir = object.transform.look().normalize();
var vel = new Vec4(dir.x * move_speed, dir.y * move_speed, dir.z * move_speed);
body.setLinearVelocity(vel.x, vel.y, 0);
// turn (in future change to random turn)
body.setAngularVelocity(0, 0, turn_speed);
body.setAngularFactor(0, 0, 0);
}
#end
}