Hello, GDScript programmers who are smarter than I,
Before I begin, please bere in mind that I am an artist trying to learn how to program. You may provide me with some explanations while assuming that I have some understanding of the concepts that you are speaking of. Please assume that I do not. You may also forget that not everyone knows that some aspects of GDScript cannot be used in certain contexts. Also, please remember that I may know fully understand the context. You may very well need to explain more than usual.
My Goal:
I want to create an Asteroids style movement system with Newtonian physics in 3D space. It would still be on along the ZX plane but rendered in 3D. (Don't ask me why, just trust that I have my reasons.) I want the ship's forward thrust to follow the physics while the rotation of the ship operates outside of physics. In other words, I want to use add_central_force() for thrust but I don't want to use add_torque() for rotation. (If you ever played Subspace/Continuum you might know what type of gameplay I'm going for. The ship rotates outside of Newtonian physics.)
My Problem:
It turns out that I can do either one or the other, but I can't do both.
I can use this code to thrust a ship in a forward direction:
extends RigidBody
var ship_z_front = -1
var ship_z_thrust = 100
func _physics_process(delta):
if Input.is_action_pressed("ui_up"):
add_central_force(transform.basis.z * ship_z_front * ship_z_thrust)
I can also use this code to rotate the ship:
extends RigidBody
var ship_rot_speed = 0.1
var ship_rot = 0
func _process(delta):
rotate_y(ship_rot)
func _input(event):
if event.is_action_pressed("ui_left"):
ship_rot += ship_rot_speed
elif event.is_action_pressed("ui_right"):
ship_rot -= ship_rot_speed
elif event.is_action_released("ui_left"):
ship_rot = 0
elif event.is_action_released("ui_right"):
ship_rot = 0
As soon as I try to use one with the other, everything stops working as expected. I don't know why. There must be a more correct way of doing this or some sort of detail that I missed. If anyone understands what I am trying to do and has a solution, please let me know.
Thanks,
CeanHuck