I have a tank on the scene with a turret attached as a child object. I also have a camera on the scene that rotates using a script, I need the tank turret to smoothly rotate as the camera rotates.
Does anyone have any ideas on how to smoothly rotate the turret after the camera, so that when the tank turns, the turret stays in place (because the camera does not rotate)
I implemented something similar, but when the tank rotates, the turret rotates with it, but since the camera does not rotate at this moment, now there is free space between the rotation of the camera and the turret.
Tank scene tree: https://i.imgur.com/BgwBz0q.png (to do camera node independent of the parent object i use this code at camera node script)
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
set_as_top_level(true)
Rotation that i need: https://youtu.be/23IdDtPB4t0
If I correctly understood your question, you have a tank which is composed of a body, which moves with WASD, and a turret linked with the camera which move with mouse movement. Since you haven't posted code, I suppose you wanna hear the concept more than the code.
The problem is how you structured your tree. You said:
I have a tank on the scene with a turret attached as a child object
Since the turret is a child of the tank, EVERY rotation, POSITION, scale update on father are applied to childs (for Godot's logic). So this is a problem, because if you rotate the tank, even the turret will rotate even if you haven't moved the mouse.
In order to fix this, you should have a tree where the father is a generic Node with two childs (two nodes), one for the turret and the camera and one for the body, both with their own script to change with user input.
This should fix this
I implemented something similar, but when the tank rotates, the turret rotates with it,
To do something "smoothly rotate" I suppose you want a system where camera rotates and after a "delay" turret rotates too. You can do so using lerp. I link to the official documentation for more
As isherwood mentioned, your question is incomplete. Please, provide more informations (and some code) if you need more assistance/what I said is not what you are searching for.
Greetings