Hello! I started testing out ChatGPT recently and it’s pretty interesting. Personally I don’t think it’s coding abilities are at a point to be extremely useful, or replace expert programmers. It’s especially not super helpful for me since I don’t know coding much at all (always struggled to retain the information I get from tutorials and demonstrations… in one ear out the other as they say). My question is: is this code I generated using Openai.com’s chatbot even remotely close to accurate or usable? is it worth struggling to get it to work or should I just stick to the nodes system, which is easier for me to grasp.
here is the code (the purpose is to update the player object’s rotation only when the left joystick input changes):
package arm;
import iron.math.Quat;
import iron.system.Input;
import iron.system.GamepadEvent;
class RotatePlayerScript extends iron.App {
private var playerObj: iron.object.Object;
private var lastX: Float = 0.0;
private var lastY: Float = 0.0;
override function init() {
super.init();
// Find the player object by name
playerObj = findObject("PlayerObject");
// Listen for gamepad input events
Input.gamepadEvent.add(onGamepadInput);
}
private function onGamepadInput(event: GamepadEvent) {
if (event.type == GamepadEvent.TYPE_AXIS && (event.id == Input.LEFT_STICK_X || event.id == Input.LEFT_STICK_Y)) {
// Get the horizontal and vertical axis values from the left joystick
var x = Input.getGamepadAxis(event.gamepad, Input.LEFT_STICK_X);
var y = Input.getGamepadAxis(event.gamepad, Input.LEFT_STICK_Y);
// Only update the rotation if the joystick input has changed
if (x != lastX || y != lastY) {
// Calculate the angle of rotation based on the joystick input
var angle = Math.atan2(y, x);
// Set the rotation of the player object to face the direction of movement
var rotation = Quat.fromAxisAngle(0, 1, 0, angle);
playerObj.getTransform().set_rotation(rotation);
// Store the current joystick input values
lastX = x;
lastY = y;
}
}
}
}