• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Object not positioning correctly on another object [HELP]

T

Thiago_Mn

Guest
Hello!

I'm making a tank game, but i just noticed that something was not right, i have 1 object that is the "Tank Body" and another object that is the "Tank Turret/Gun" and how I'm trying to make a 2D game where the camera is on top, i had the idea of putting an angle where the tank is aiming to the mouse but the gun was not positioning right because of the Origin of the "Tank Body" sprite and the "Tank Turret/Gun", the Turret/Gun was out of position in the body, because of the angle where the tank was directing to, and i don't know how to solve this. Is there a way to the Turret/Gun stay in the same position when the "Tank Body" has change of angle?

Any help, i would be thankful! :)

Edit:Sorry for my bad english.

Here's a screenshot:gunsb.png
 
Last edited by a moderator:

TheouAegis

Member
Set the tanks angle to zero. Place the turret where you want it relative to the tank. Now get the direction and length from the tank origin to the turret origin. save these values in either the tank or the turret, whoever is going to be updating the turret position. When you snap the turret to the tank you can use the lengthdir functions using the length you saved and adding the angle you saved to the tank's image_angle.

Tip: if for whatever reason you were going to limit the number of angles the tank can go to, you can save time by free calculating all of the lengthdir offsets and storing them in an array.
 
T

Thiago_Mn

Guest
Set the tanks angle to zero. Place the turret where you want it relative to the tank. Now get the direction and length from the tank origin to the turret origin. save these values in either the tank or the turret, whoever is going to be updating the turret position. When you snap the turret to the tank you can use the lengthdir functions using the length you saved and adding the angle you saved to the tank's image_angle.

Tip: if for whatever reason you were going to limit the number of angles the tank can go to, you can save time by free calculating all of the lengthdir offsets and storing them in an array.
I'm sorry to ask you, but could you try to show me a code example? i'm very noob on it, and also i don't speak english either.
(I'm really confused on what you said up there, i just understanded somethings and one of these things didn't worked when i tried.)
 
Last edited by a moderator:
Top