- Edited
why in this code the rotation axis works diferent? like the axis rotate with the cube as well
extends Spatial
var target_position = Vector3()
var varAlph = 0.0
func _process(delta):
rot()
movement1(delta)
func rot():
$MeshInstance.rotation_degrees = lerp($MeshInstance.rotation_degrees, target_position, varAlph)
if varAlph <= 1:
varAlph += .01
if Input.is_action_just_pressed("ui_left"):
target_position.z = $MeshInstance.rotation_degrees.z + 90
varAlph = 0.0
if Input.is_action_just_pressed("ui_right"):
target_position.z = $MeshInstance.rotation_degrees.z - 90
varAlph = 0.0
if Input.is_action_just_pressed("ui_up"):
target_position.x = $MeshInstance.rotation_degrees.x - 90
varAlph = 0.0
if Input.is_action_just_pressed("ui_down"):
target_position.x = $MeshInstance.rotation_degrees.x + 90
varAlph = 0.0
but in this one, the axis rotate in other way, the way that i want like the game bloxorz
extends RigidBody
var target_position = Vector3()
var varAlph = 0.0
var basis = Basis()
func _ready():
print($MeshInstance.rotation_degrees)
func _physics_process(delta):
$MeshInstance.rotation = lerp($MeshInstance.rotation, target_position, varAlph)
if varAlph <= 1:
varAlph += .01
if Input.is_action_just_pressed("ui_left"):
$MeshInstance.rotate(-basis.z, deg2rad(90))
print($MeshInstance.rotation_degrees)
varAlph = 0.0
if Input.is_action_just_pressed("ui_right"):
$MeshInstance.rotate(basis.z, deg2rad(90))
print($MeshInstance.rotation_degrees)
varAlph = 0.0
if Input.is_action_just_pressed("ui_up"):
$MeshInstance.rotate(basis.x, deg2rad(90))
print($MeshInstance.rotation_degrees)
varAlph = 0.0
if Input.is_action_just_pressed("ui_down"):
$MeshInstance.rotate(-basis.x, deg2rad(90))
print($MeshInstance.rotation_degrees)
varAlph = 0.0