Realistic tank movement.

N

Nairem Legacy

Guest
Can someone give me a hand I am trying to make a tank function realistically as in when the player moves away from the front of the tank the tank will have to stop and turn toward the player then continue its pursuit.
 
Well, I would have two directions, target_direction and current_direction. Target_direction would just point wherever the tank wants to go (so at the player, a waypoint, whatever). Then current_direction would slowly adjust itself to face target_direction (there's a nifty piece of code in the manual under the angle_difference() function for that...if you use that code snippet, you would swap the pd variable for target_direction and image_angle for current_direction). Then the tank would only start applying movement when target_direction and current_direction are equal (or perhaps within a certain range of each other).
 
N

Nairem Legacy

Guest
ERROR in
action number 1
of Step Event0
for object obj_Enemy:

Variable <unknown_object>.current_direction(100019, -2147483648) not set before reading it.
at gml_Object_obj_Enemy_Step_0 (line 4) - var pd = current_direction(x,y,mouse_x,mouse_y);
############################################################################################
gml_Object_obj_Enemy_Step_0 (line 4)


Still having problems and just wanna let you know I am new to coding so most of this don't make sense I am trying to make sense of it.

here is the full code:
// Movement
if (instance_exists(obj_Player))
{
var pd = current_direction(x,y,mouse_x,mouse_y);
var dd = angle_difference(current_direction, pd);
current_direction -= min(abs(dd), 10) * sign(dd);
current_direction = (obj_Player);
}
 
Last edited by a moderator:
A realistic tank would have the turret and the actual tank rotating separately, the turret pointing to the enemy direction, and the tank in the moving direction. You would have to use a separated tank and turret sprite for this. Tanks do not have to stop to change direction.

And your error says you don't have a variable named current_direction declared.
 
N

Nairem Legacy

Guest
Ok yea sorry been busy was not able to reply quickly, but yea your right Slow Fingers I am trying to make it where when someone is playing the game the tank don't slide all over the place sorry for the confusion. And Refresher Towel I do not understand what you are trying to explain sadly I hardly know anything about coding.
 

Nidoking

Member
I hardly know anything about coding.
I think I found the main problem you need to solve.

By the way, did you enjoy the Spot the Difference game I posted above? Did you find the difference between the two quotes? I promise you'll get farther indulging me in this than you will continuing to be confused.
 
Worst case scenario if you can't get your turret to work properly, make your game about self-propelled artillery guns, they were pretty much tanks without a rorating turret. Problem solved. :banana:

EDIT: I felt bad for that answer, so I made you an example with simple code.
Notice the origin of the sprites (tank and turret). There's also some simple code that will show you how to make your shells pop from the tip of the gun.
I snuck some debug functions in there so you can adjust for best values while in-game. Hope that helps
 
Last edited:
Top