Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Nazzaroth |
So i’ve started a new game project that has an oldschool 3d dungeoncrawler map.
Made dungeon with gridmap all fine.
Now i want to make playermovement in set steps. Everytime the player hits
a button he moves to the next cell in the grid. The movement is also supposed to be
smooth so i interpolate the movement.
This is the code i have so far for forward movement and left turn:
extends KinematicBody
var t = 0.0
var forwardFlag
var leftTurnFlag
var playerPoint = self.transform
var forwardPoint = self.transform
var leftTurnPoint = self.transform
func _ready():
#changing target points for later interpolation
forwardPoint.origin += Vector3(0,0,-2)
leftTurnPoint = leftTurnPoint.rotated(Vector3(0,1,0), deg2rad(90))
leftTurnPoint = leftTurnPoint.orthonormalized()
print(self.transform)
print(leftTurnPoint)
func _physics_process(delta):
if Input.is_action_just_pressed("forward"):
forwardFlag = true
if Input.is_action_just_pressed("left"):
leftTurnFlag = true
if forwardFlag:
t += delta
self.transform = self.transform.interpolate_with(forwardPoint,t)
print(self.transform.basis)
print(forwardPoint.basis)
if self.transform == forwardPoint:
forwardFlag = false
#update coresponding Point
forwardPoint.origin += Vector3(0,0,-2)
#reset t for interpolation speed
t = 0
if leftTurnFlag:
t += delta
self.transform = self.transform.interpolate_with(leftTurnPoint,t)
print(self.transform.basis)
print(leftTurnPoint.basis)
if self.transform == leftTurnPoint:
leftTurnFlag = false
#update coresponding Point
leftTurnPoint = leftTurnPoint.rotated(Vector3(0,1,0), deg2rad(90))
leftTurnPoint = leftTurnPoint.orthonormalized()
print(self.transform)
print(leftTurnPoint)
#reset t for interpolation speed
t = 0
The forward movement works fine and dandy but for the rotation there comes up this problem:
When i print out each transform.basis values:
player: ((0, 0, 1), (0, 1, 0), (-1, 0, 0))
target: ((-0, 0, 1), (0, 1, 0), (-1, 0, -0))
the check if the interpolation is done isnt possible because the target.basis has -0 values.
The big question now is: Why?
Is there a reason why we have 0 and -0 values in these Datatypes?
And if this is by design and important is there:
a) a better way to accomplish my goal
or b) a more efficient way to test the end of interpolation than to go through the
target.basis and reset each -0 to 0 each time
Thanks a lot for anyone that can help with this.