- Edited
Hello! I've been stumped on a core part of my game project for the past couple of days. It basically boils down to: I'm trying to figure out a good way to have the player orbit another object using A and D, but also be able to get closer or farther from it using W and S, as a sort of "lock-on system". I'm not really good when it comes to 3D things or math, and I've exhausted my extent of personal and Google knowledge. I've got some code below but all it was for was the orbiting feature and I'm all for scrapping it if there's a better way. Thank you in advance!
var move_base = .05
var move_dist = (Input.get_action_strength("move_down") - Input.get_action_strength("move_up")) * move_base
var move_orb = (Input.get_action_strength("move_right") - Input.get_action_strength("move_left")) * move_base
# Rotation variables
# Subtract origin point from target's position
var pivot_radius = Vector3.ZERO - target.global_translation
var pivot_transform = Transform(transform.basis, target.global_translation)
# Rotate around target
transform = pivot_transform.rotated(Vector3(0, 1, 0), move_orb).translated(pivot_radius)
As well as that I've also attached a picture with the core idea of what I'm trying to do, that being having a player orbit along the red circle as well as being able to get closer or farther from the selected enemy along that line that bisects them.