• 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!

GML [SOLVED] Tank Control Assistance Seeked.

Dividious

Member
Got a scenario that I cant solve...

top down game
wasd controls the bottom image of a man
mouse controls the top image of a man

i want to be able to code where i have the mouse to the right of the player, so he's looking right as well as the bottom half also facing right.... but if i push down on "S" and keep the mouse to the right of the player character then the lower half will slightly rotate to walk down but be locked within a certain degree of the top half facing direction. i'm using motion_add() for movement.

its similar to this video:
however i want the "tank" to be moved via wasd and the "turret" to be moved via mouse, and the tank to be locked to the turret. unlike the video where the turret is locked to the tank.

see image for example:


any help would be appreciated
 

Attachments

Roldy

Member
What are you having problems with?

Post the code you have. Describe what is going wrong.
 

Psycho_666

Member
2 things buddy.
1. Make the bottom and the top part to face the mouse. Then when you press the direction keys check if the movement direction so different than the angle the mouse is pointing and add or subtract let's say 45 degrees.
Point direction is the thing that will help you.
2. You may want to change the title of this thread because the current title is not good at all.
 

Yal

šŸ§ *penguin noises*
GMC Elder
however i want the "tank" to be moved via wasd and the "turret" to be moved via mouse, and the tank to be locked to the turret. unlike the video where the turret is locked to the tank.
The tutorial should've already taught you everything you need to know about tank controls, mouse-based aiming, and locking objects together. Try watching it again, listening to what the tutor has to say instead of blindly copypasting the code examples. Have you tried just swapping the code around between the two objects?
 

Dividious

Member
2 things buddy.
1. Make the bottom and the top part to face the mouse. Then when you press the direction keys check if the movement direction so different than the angle the mouse is pointing and add or subtract let's say 45 degrees.
Point direction is the thing that will help you.
2. You may want to change the title of this thread because the current title is not good at all.
3 things Fwiend.

1. cool beans, 0 - 45 equals (-45) unfortunately it doesnt equal the proper degree šŸ¤”
2. Title changed, if it doesnt suffice with you let me know a better one.
3. you come off as rude...

The tutorial should've already taught you everything you need to know about tank controls, mouse-based aiming, and locking objects together. Try watching it again, listening to what the tutor has to say instead of blindly copypasting the code examples. Have you tried just swapping the code around between the two objects?
Thanks Yal... I'm aware of the controls for twin stick. Unfortunately I did not copy paste that code.. as i was merely saying its a similar goal as what he was doing but reverse. I did however just try and then i tried your recommendation of flipping, it was not successful... it was very glitchy it worked out decently on keyboard and mouse however control and joystick was the glitchy issue. tryin to do stuff at 2am may not be the brightest idea for me...

i came up with:

Player Create Event:
GML:
legdir = 0;
scripts section in scr_kb
GML:
legdir = point_direction(0,0,x_speed,y_speed);
scripts section in scr_kb
example missing other things not referencing the topic at hand
GML:
if (left_key) {
    if (up_key) {
        legdir = 135;
    }
    if (down_key) {
        legdir = 225;
    }
}
etc, etc, etc...

of course script is called by player to update the legdir variable upon inputs

Player Draw Event:
GML:
draw_sprite_ext(sprLegs,legindex,x,y,image_xscale,image_yscale,legdir,image_blend,image_alpha);
very crude but works... plus not like people will be picking thru the code anyways, however a cleaner method would be great.. eh c'est la vie...
 
Top