I am trying my hand at recreating the classic 90’s Unix game XTank.
So far, I have tank I can drive around with the arrow keys, and an arena made up of tiles. The tiles have the collision areas defined, now I just need the tank to actually stop when it hits something.
Can anyone recommend a 2D tutorial that adresses how to have a object/vehicle moving around in a maze?
The CharacterBody2D and Click-and-move section of the manual got me to almost where I need to be.
The biggest issue I still have us that collisions are behaving differently depending on how fast the tank is moving.
The tank moving very slow gives me this:
If I crank up the speed, the tank gets embedded in the wall.
Other than this behavior, I’m thrilled with how this is turning out.
Now I need to figure out how do “traction”, so the tank slides just a little bit when turning.
Acceleration is another thing I need to deal with. The tank’s speed shouldn’t instantly go from 0 to 9. It should take a little bit to accellerate from a standstill to full speed. Same with slowing down.
The final thing I need to figure out is how to have the tank “bounce” some when it hits a wall.
The downside of the original XTank game being so ancient is that I doubt very much that any there’s video of the game actually running to show the nuances of how the tanks moved.
I’ve contacted around 10 people that I worked with back in 1995, and I’ve at least been able to get the customized version of the code and some of the configuration files we used.
After a boatload of updates (Imake anybody?), I’ve been able to get our customized version the game compiled and starting, but the configuration still needs to be sorted out.
This turning out to be one hell of a project just to satisfy a deeply sentimental urge
EDIT: Forgot the script that’s handling movement. Including it in case anyone wants to point out how bad it is:
extends CharacterBody2D
@export var speed = 0
var target = position
func is_numeric_key(value):
return ((value >= KEY_0) && (value <= KEY_9))
func keycode_to_speed(code):
return(100 * (code - 48))
func _input(event):
if event is InputEventKey && event.pressed:
if event.keycode == KEY_ESCAPE:
get_tree().quit()
elif is_numeric_key(event.keycode):
speed = keycode_to_speed(event.keycode)
# Use is_action_pressed to only accept single taps as input instead of mouse drags.
if event.is_action_pressed(&"click"):
target = get_global_mouse_position()
look_at(target)
func _physics_process(delta):
velocity = transform.x * 1 * speed
move_and_slide()