Bingdom
Googledom
Hello GMC!
I'm currently working on a top-down block physics spaceship prototype. I've run into an issue where I'm having trouble figuring out a great way to activate the correct thrusters to effectively rotate the ship. I've got a working method, but it only works on certain designs.
Here's an example of it not working. (It's meant to be turning clockwise). (Activated thrusters are red). It is trying to rotate the ship 180 degrees away from the mouse.
Note: The little orange arrow in the middle of the ship is the direction the ship is facing.
The centre of mass is located here (The orange circle):
I'm not exactly sure what's causing the incorrect rotation. It could be the heavier side having more thrusters.
Another example. This one is meant to be turning clockwise, but it's turning the opposite way. (COM is at the centre)
An example of it working
Why did I show you multiple designs? I do believe it's got something to do with my code and how it behaves.
This is the code I'm using to calculate the direction of the thruster.
The system I'm using is that thrusters either have a -1 or 1 value (Turn either left or right). The main block compares the angle between where the whole ship is facing, and the angle from it's location to the mouse. If the result is 1, thrusters that contain a value of 1 will activate, same with thrusters if they had a value of -1.
I am pretty sure the code behind that is fine, just assigning the correct direction of the thrusters is a problem.
Probably not a great system, as some thrusters will be better off not running 100% thrust due to the COM.
Thank you for reading.
I'm currently working on a top-down block physics spaceship prototype. I've run into an issue where I'm having trouble figuring out a great way to activate the correct thrusters to effectively rotate the ship. I've got a working method, but it only works on certain designs.
Here's an example of it not working. (It's meant to be turning clockwise). (Activated thrusters are red). It is trying to rotate the ship 180 degrees away from the mouse.
Note: The little orange arrow in the middle of the ship is the direction the ship is facing.
The centre of mass is located here (The orange circle):
I'm not exactly sure what's causing the incorrect rotation. It could be the heavier side having more thrusters.
Another example. This one is meant to be turning clockwise, but it's turning the opposite way. (COM is at the centre)
An example of it working
Why did I show you multiple designs? I do believe it's got something to do with my code and how it behaves.
This is the code I'm using to calculate the direction of the thruster.
Code:
with(oThruster) {
var h, v,
//Calculate coordinates for the centre of mass
com_x=other.x+other.com_Px, com_y=other.y+other.com_Py;
//Now calculate how far away the thruster is from the centre of mass.
h=(x-com_x); //Horizontal axis
v=(y-com_y);
//Find out which one of the thruster's axis is closer to the COM
if abs(h) < abs(v) {
//Closer to the COM on the x axis
ang=sign(h*v);
} else {
//Closest on y axis
ang=sign(v*-h);
}
//-1 for turning left (CCW), 1 for turning right (CW) (Works with angle_difference(phy_rotation,-point_dir(x,y,mouse_x/y)
}
I am pretty sure the code behind that is fine, just assigning the correct direction of the thrusters is a problem.
Probably not a great system, as some thrusters will be better off not running 100% thrust due to the COM.
Thank you for reading.
Last edited: