Making a top down car racer in Godot

Introducing variables Constants, This section is work in progress Direction vector, speed vector, current turn… Rotating the direction vector Option 1: Calculating it from an angle Option 2: Maybe faster Needs to be normalized perpendicular vector work in progress Full code Car.gd extends KinematicBody2D const max_speed_forward = 40000 const max_speed_backwards = 15000 const accel = 0.5 const deaccel = 0.4 const deaccel_break = 0.7 var current_direction = Vector2(0, -1) var rotation_speed = 5 var current_speed = 0 var current_turn = 0 func perpendicular_vector(vec: Vector2): return Vector2(vec.y, -vec.x) func _physics_process(delta): # Change forward velocity based on up and down input if Input.is_action_pressed("ui_down"): if current_speed < 0: # When we go forward current_speed += deaccel_break * delta elif current_speed < 1: # When we go backwards current_speed += accel * delta elif Input.is_action_pressed("ui_up"): if current_speed > -1: current_speed -= accel * delta else: # When player isn't holding anything, deaccelerate if current_speed < -0.01: # When we go forward current_speed += deaccel * delta elif current_speed > 0.01: # When we go backwards current_speed -= deaccel * delta else: # STOP current_speed = 0 # Setting the current turn direction if Input.is_action_pressed("ui_left"): current_turn = delta elif Input.is_action_pressed("ui_right"): current_turn = -delta else: current_turn = 0 # Add a scaled down perpendicular vector of current dirrection to the direction. # This will result in changing the direction vector each frame when player is holding # right/left keys # Multypling by current speed is optional (This way you prevent turning around on one place) current_direction += perpendicular_vector(current_direction) * current_turn * rotation_speed * -current_speed # Normalize the vector, so the direction is preserved but size remains the same. # This prevents acceleration bug current_direction = current_direction.normalized() # Visual rotation of our kinematic body. I add 90 because of the direction my car sprite is turned rotation_degrees = rad2deg(current_direction.angle()) + 90 # Application of the result movement var move_vector = current_direction * -current_speed * delta if current_speed > 0: move_vector *= max_speed_backwards else: move_vector *= max_speed_forward move_and_slide(move_vector)

March 31, 2021 · 2 min · Me

Teaching zoomers how to code

The problems A lot of kids (12-13yo) start to attend my lessons because they think they want to do programming but then they come and start minecraft instead of focusing just a little bit. It’s hard to tear them away from it because I am not the type of person that would force them to do something. Getting their focus It’s hard to make kids focus to anything. They want to do fun stuff, and coding basics in Python may not seem just as fun as Minecraft to the average kid. I know it myself, when I think something is boring, I don’t focus at all - We are forced to attend classes like Czech language so I know my things. ...

March 30, 2021 · 5 min · Me

coding Proburese.cz

The idea So approximately three weeks ago some people started sending tons of small donates to our governing partys transparent account. And they always write a funny/hate message in the payment details. See, elections in Czechia are approaching. They’ll start in a half of a year from now. And some poeple are very pissed of the current goverment. It’s not just the corrupt prime minister. Now it’s also the fact that we are “best in covid” and many lives have been lost because of it. ...

March 29, 2021 · 6 min · Me

CMake stuff

I just copy random things into CMakeLists.txt to make it work. I will write it up here so next time i won’t have to struggle with it again. I am very nooby in the C++ world and i don’t really understand CMake so please don’t judge me. The main reason I use it because i need to generate compile-commands.json for clangd, so I can have working autocomplettion in neovim using coc.nvim and coc-clangd. ...

February 28, 2021 · 2 min · Me

Think about space

I watched some of melodysheep’s videos recently - a friend sent me a link to the Timelapse of the future. Even though I watched it last year, i hit play, and it blown my mind once again. I had to watch all his space stuff. I have to say, these guy’s videos are on another level. It’s not just the quality of the animation, sound and speech that makes these videos so interesting. It’s about the thought, that our planet isn’t the only place where events happens. ...

February 27, 2021 · 3 min · Me

How to: Godot parallax backgrounds

What is a parallax background? Parallax is a effect you can use for your background in your 2D platformer game. You can make layers of background images, each of them can scroll in a different speed. That creates a nice illusion of depth. Take a look at this video: Sorry, your browser doesn't support embedded videos. As you can see, we have drawn several layers of background in our game Vagos Dream, and then used the godot ParallaxBackground node to handle the scrolling. It looks really nice. ...

February 27, 2021 · 3 min · Me

My projects

koronagrafy: charts with coronavirus stats of czech republic. made in march 2020 Subtitle translator simple Vue site that can translate your movie subtitles into desired language School canteen app Android app to order lunch in my school. Utilizes an complicated python API that interacts with the canteen’s web app using selenium. Proburese.cz “this week i’ll make a site that’ll go viral on czech internet” Games and stuff Mission: Sacriffice Vagos Dream Lissajous C++ plotter

February 27, 2021 · 1 min · Me