heos666 Posted April 7, 2023 Share Posted April 7, 2023 Я нашел код для поворота объекта public float movement_speed = 5.0f; // define the rotation speed public float rotation_speed = 70.0f; private void Init() { ControlsApp.SetStateKey(Controls.STATE_AUX_1, Input.KEY.A); ControlsApp.SetStateKey(Controls.STATE_AUX_2, Input.KEY.D); } private void Update() { // get the frame duration float ifps = Game.IFps; // enable visualizer Visualizer.Enabled = true; // get the current world transform matrix of the mesh Mat4 transform = node.WorldTransform; // get the direction vector of the mesh from the second column of the transformation matrix Vec3 direction = transform.GetColumn3(1); // initialize rotation and movement and update flag Mat4 rotation = Mat4.IDENTITY; Vec3 delta_movement = new Vec3(0.0f); bool update_transform = false; // render the direction vector for visual clarity Visualizer.RenderDirection(node.WorldPosition, new vec3(direction), new vec4(1.0f, 0.0f, 0.0f, 1.0f), 0.1f, false); // check if the control key for left rotation is pressed if (ControlsApp.GetState(Controls.STATE_AUX_1) == 1) { // set the node's left rotation along the Z axis rotation.SetRotateZ(rotation_speed * ifps); update_transform = true; } // check if the control key for right rotation is pressed else if (ControlsApp.GetState(Controls.STATE_AUX_2) == 1) { // set the node's right rotation along the Z axis rotation.SetRotateZ(-rotation_speed * ifps); update_transform = true; } // update transformation if necessary if (update_transform) { // combine transformations: movement + rotation transform = transform * rotation; transform.SetColumn3(3, transform.GetColumn3(3) + delta_movement); // set the resulting transformation node.WorldTransform = transform; } Но объект поворачивается относительно края объекта, как можно сделать поворот объекта на одном месте Link to comment
mifril Posted April 7, 2023 Share Posted April 7, 2023 Здравствуйте, Вы проверяете этот скрипт на каком-то своем объекте? Попробуйте создать куб в редакторе и проверить этот скрипт на нем, поврот относительно края объекта может быть связан с неправильным pivot'ом этого объекта. Проверить pivot можно в редакторе: Link to comment
Recommended Posts