0 votes

As a hobbyist, I decided to make a 3D game for fun.

I wanted a lock-on system and achieved this by using a spatial node as a pointer. The idea is whenever a key was pressed, the pointer will teleport to the coordinates of an enemy.
This pointer is always at the center of the camera, and the body will occasionally face the pointer and therefore move relative to it. To do this I used look_at() and then used rotated():

look_at($"../CameraBase/Pointer".get_global_transform().origin, Vector3(0, 1, 0))
velocity = velocity.rotated(Vector3(0, 1, 0), rotation.y)

I know I should use a variable to reference the pointer node but I did this for testing sake.

I also wanted accelerating and decelerating player movement, so I used linear_interpolate() to simulate that:

if input: # accelerate
    velocity = velocity.linear_interpolate(input, .1)
else: # decelerate
    velocity = velocity.linear_interpolate(Vector3(), .1)

Attempting to both rotate and linearly interpolate the kinematic body gets really strange. Almost all the time, if the body is not facing the negative z-axis, then the speed becomes extremely slow.

I can only identify that rotating the body somehow alters the interpolation's calculation, but I don't understand how so and therefore don't understand how to fix it.
Is there a more efficient way of having a lock-on system or is there a fix for this?

asked May 30 in Engine by bellpepper (17 points)
edited May 31 by bellpepper

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.