Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1412192 Posts in 69756 Topics- by 58693 Members - Latest Member: NebulaFlare

January 24, 2025, 04:21:34 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Aircraft Movement (GML)
Pages: [1]
Print
Author Topic: Aircraft Movement (GML)  (Read 3211 times)
Exye
TIGBaby
*


View Profile
« on: August 05, 2024, 03:21:25 PM »

I've been looking for an answer to this, I keep finding super complicated solutions that don't do what I want. My thoughts are this should be simpler than what I'm finding, or maybe I don't know the best syntax for researching (Google, Stack, GPT)

I want the aircraft to fly like a drone. So the left stick would move forward, backward, left and right (headless) however the craft is angled.

The right stick would turn the craft (image_angle). This is what I have so far, I'm newish to programming and completely new to Gamemaker. Where I'm stuck is finding a way to move the craft side to side with the left stick. I thought motion_add(image_angle -.45), like motion_add/image_angle moves the craft forwards and backwards using pos and neg values but to move it left would be a percent or fraction of the image_angle. I think I'm making sense.

var gamepad_index = 0;
var acc_ship = gamepad_axis_value(gamepad_index, gp_axislv);
var acc_ship_side = gamepad_axis_value (gamepad_index, gp_axislh);
var turn_ship = gamepad_axis_value(gamepad_index, gp_axisrh);



// Headless movement with Left Stick (only forwards and backwards(clarification for the purpose of this post))
if (acc_ship < -0.1){
   motion_add(image_angle, 0.1);
}

if (acc_ship > 0.1){
   motion_add(image_angle, -0.1);
}

//Again for the purpose of this post I was thinking, the .45 being 45 degrees less than the actual image angle, how would I write that, or express that idea. Do I need to totally map the craft differently to begin with?

if (acc_ship_side > 0.1{
        motion_add(image_angle - .45, 0.1);
}


// Turning Ship with Right Stick

if (turn_ship < -0.1){
   image_angle += 4;
}

if (turn_ship > 0.1){
   image_angle -=4;
}

Thank you for your time, I've been wrestling with this for days trying to figure it out on my own. I've done a handful of tutorials trying to grasp the basics. I studied a book on C on my own to learn programming principles, finished the Odin Project and CS50 and did a few small projects before starting game dev with gamemaker, for context.
Logged
salade
Level 4
****



View Profile
« Reply #1 on: September 10, 2024, 11:58:29 AM »

I was going to recommend my solution that I am using in Godot, but then I realized that Game Maker doesn't seem to have built in support for vectors, so you are going to have a lot of trouble.

Just watch this video and it will give a much better approach:

Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic