So I have made a ruff 2D physics engine. You play as a tank and there are hills/different terrains you can drive up/down and ramp, etc...
Anyways, the tank and the gun are separate objects and the gun "connects"(follows x,y) to the tank and it has a max pitch and max yaw. When my tank is on flat ground my system for max yaw and pitch work fine, but my tank's angle changes as it drives uphill or downhill the max yaw and pitch don't adjust with the tanks's angle(Therefore I get the gun sticking out underneath the tank when I drive uphill and not aiming down as I drive downhill.)
This is what I have in-place right now for max yaw and pitch of the gun on flat ground:
image_angle=point_direction(x,y,mouse_x,mouse_y)
if(image_angle >=0 && image_angle <=50)//where my mouse has to be within before my gun will aim towards it.
{
image_angle=point_direction(x,y,mouse_x,mouse_y)
}
else if(image_angle <180)//if my mouse is anywhere but within ^^ make it aim up
{
image_angle=50
}
else //if it is anywhere else aim down
{
image_angle=355//makes the gun aim down a little more then straight across
}
I have tried:image_angle (>,<,=)obj_player.image_angle+(The number I have after the "<,>,=")
Hoping it would adjust with my angling tank but it had MANY problems. Only thing that fixed was the gun's max pitch as it drove uphill(Meaning it didn't aim through the tank's underbelly) but it only made the gun fling around on flat and inverted land(going down). PLEASE HELP ME! I am not very good at this kind of math.
My sprites(tank and gun) look like this when they are at angle 0:
'''''_____
__|____|=====]
|_________\
(_O__O__O_)
Also, when my mouse is on the left side of the tank the turret flips and the gun changes positions/flips. It is the same code as up there but just with different angles.
*I am using GM8, NOT 8.1*
Edited by Dalton Fox, 09 March 2012 - 02:48 AM.











