Skip to main content
  1. Blogs/

Make a Google Chrome T-Rex Style Side Scroller in Godot

7 mins
Game Dev Godot Side Scroller 2d Tutorial
Table of Contents

Creating a Chrome T-Rex style endless runner in Godot involves implementing several core game systems that work together to create the classic side-scrolling experience 1. This comprehensive guide will walk you through building all the essential components, from player physics to obstacle spawning and background scrolling.

Chrome T-Rex style side-scrolling game with a dinosaur jumping over cacti obstacles

Chrome T-Rex style side-scrolling game with a dinosaur jumping over cacti obstacles

Game Overview and Core Mechanics
#

The Chrome Dinosaur Game is an endless runner where the player controls a pixelated T-Rex that continuously moves from left to right across a desert landscape 2. The gameplay revolves around avoiding oncoming obstacles such as cacti and pterosaurs by jumping or ducking 2. The game gradually increases in speed until the player hits an obstacle, triggering an instant game over 2.

The core mechanics include gravity-based jumping physics, collision detection with obstacles, parallax background scrolling, and progressive difficulty scaling 1. In Godot, this translates to using CharacterBody2D for player movement, Area2D nodes for obstacle detection, and ParallaxBackground for the scrolling environment 34.

Project Setup and Scene Structure
#

Begin by creating a new Godot project and setting up the main scene structure 5. The recommended node hierarchy follows a modular approach that separates different game systems for better organization and maintainability 1.

Godot node tree structure diagram for a side-scrolling T-Rex style game

Godot node tree structure diagram for a side-scrolling T-Rex style game

The main scene should contain a Node2D as the root, with child nodes including the Player (CharacterBody2D), Background (ParallaxBackground), Ground (StaticBody2D), ObstacleSpawner (Node2D), and UI (CanvasLayer) 53. This structure allows each system to operate independently while communicating through Godot’s signal system and node groups 3.

Configure the project settings to handle pixel art properly by setting the texture import filter to “Off” for crisp pixel graphics 5. Set up input actions for “jump” (Space/Up Arrow) and “duck” (Down Arrow) in the Input Map section of Project Settings 51.

Player Character Implementation
#

The player character uses CharacterBody2D for precise movement control and collision handling 3. CharacterBody2D is ideal for character controllers because it provides built-in methods like move_and_slide() and is_on_floor() while allowing complete control over physics behavior 36.

The player script implements gravity-based physics where velocity increases downward over time until the character hits the ground 7. Jump mechanics use a fixed velocity applied upward when the jump input is pressed, but only while on the ground to prevent infinite jumping 37. The ducking mechanic adjusts the collision shape dynamically and can provide faster falling when pressed mid-air 1.

Animation state management switches between idle, running, jumping, ducking, and death animations based on player state and input 58. The collision system uses layer 1 for the player and layer 2 for obstacles, with appropriate masks set for detection 93.

Obstacle System and Spawning
#

The obstacle system consists of two main components: individual obstacle scenes and a spawner that manages their creation and timing 110. Each obstacle extends Area2D for collision detection without physical collision response, allowing the player to pass through while triggering game over events 9.

Obstacles move from right to left at a speed that increases over time, creating progressive difficulty 111. The spawner uses a Timer node to create obstacles at random intervals, with spawn timing becoming more frequent as the game progresses 10. Different obstacle types (ground-based cacti and flying pterodactyls) can be randomly selected from an array of preloaded scenes 1.

The collision detection system uses the body_entered signal from Area2D to detect when the player character enters an obstacle’s collision area 912. When a collision occurs, the obstacle calls the player’s die() method, which triggers the game over sequence 1.

Background and Parallax Scrolling
#

The parallax background system creates depth illusion by moving multiple layers at different speeds 13414. ParallaxBackground serves as the container node, with ParallaxLayer children containing Sprite2D nodes for different visual elements 415.

Each layer has different motion_scale values: distant elements like sky and clouds move slowly (0.1-0.3), middle elements like hills move at medium speed (0.5), and foreground elements like ground move at full speed (1.0) 1416. The motion_mirroring property enables seamless infinite scrolling by automatically repeating textures when they move off-screen 14.

The background can scroll automatically without camera movement by modifying the scroll_offset property in a script attached to the ParallaxBackground node 1715. Day and night cycles can be implemented by changing the modulate color of sprite layers at regular intervals 1.

Game State Management
#

A centralized GameManager handles all game states including start, running, game over, and restart phases 181. This manager coordinates between all game systems using Godot’s group system and signals for clean communication 3.

The scoring system uses a Timer that increments the score at regular intervals while the game is running 19. High scores are saved to a file using Godot’s FileAccess class for persistence between sessions 1. Game state transitions are triggered by input events and collision detection, with proper cleanup of obstacles and player state reset during restarts 20.

Visual feedback includes score display, high score tracking, game over messages, and start instructions through a UI system built with CanvasLayer and Control nodes 19. Sound effects for jumping and game over events enhance the player experience 1.

Physics and Movement Refinement
#

Fine-tuning the physics requires balancing gravity strength, jump velocity, and game speed for satisfying gameplay 721. The gravity value should feel substantial enough to create weight but not so strong that jumps feel floaty or uncontrollable 7. Jump height and time can be calculated mathematically using projectile motion formulas for precise control 7.

Variable jump heights can be implemented by allowing the player to control jump duration through input timing 7. Coyote time (brief grace period for jumping after leaving a platform) and jump buffering (allowing jump input slightly before landing) improve the game feel significantly 22.

The ground collision uses StaticBody2D with CollisionShape2D to create solid surfaces that interact properly with the CharacterBody2D player 323. Collision layers and masks must be configured correctly to ensure proper interaction between player, obstacles, and environment 2425.

Advanced Features and Polish
#

Progressive difficulty scaling adjusts spawn rates, obstacle speeds, and variety over time to maintain engagement 111. The original Chrome game switches between day and night modes every 700 points, which can be replicated through background color modulation 2.

Object pooling can optimize performance by reusing obstacle instances instead of constantly creating and destroying them 26. This becomes important as game speed increases and obstacles spawn more frequently 11.

Visual effects like screen shake on collision, particle effects for dust clouds, and smooth camera following enhance the polish level 5. Sound design with jumping sounds, collision effects, and ambient background audio creates a more immersive experience 1.

Testing and Optimization
#

Playtesting reveals balance issues with jump timing, obstacle spacing, and difficulty progression 1. The game should feel challenging but fair, with obstacles spaced appropriately for the current movement speed 11. Performance optimization focuses on efficient sprite rendering, minimal garbage collection from object creation, and smooth frame rate maintenance 26.

Mobile adaptation requires touch input handling for jump and duck actions, with visual touch indicators for better usability 2. Screen scaling considerations ensure the game works across different device resolutions while maintaining pixel-perfect rendering 5.

Conclusion
#

Building a Chrome T-Rex style side scroller in Godot demonstrates many fundamental game development concepts including physics-based character controllers, procedural content generation, state management, and performance optimization 31. The modular approach using separate scenes for different game components creates maintainable code that can be easily extended with new features 5.

The key to success lies in iterative development, starting with basic movement and collision detection, then gradually adding features like scoring, background scrolling, and visual polish 111. Godot’s node-based architecture and built-in physics systems provide excellent tools for this type of game, making it an ideal project for learning game development fundamentals 35.


  1. https://www.youtube.com/watch?v=nKBhz6oJYsc ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  2. https://en.wikipedia.org/wiki/Dinosaur_Game ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  3. https://docs.godotengine.org/en/stable/tutorials/physics/using_character_body_2d.html ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  4. https://docs.godotengine.org/en/stable/classes/class_parallaxbackground.html ↩︎ ↩︎ ↩︎

  5. https://www.youtube.com/watch?v=43c-Sm5GMbc ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  6. https://docs.godotengine.org/en/stable/classes/class_characterbody2d.html ↩︎

  7. https://www.youtube.com/watch?v=IOe1aGY6hXA ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  8. https://www.youtube.com/watch?v=mnXfuoWPEiI ↩︎

  9. https://docs.godotengine.org/en/stable/tutorials/physics/using_area_2d.html ↩︎ ↩︎ ↩︎

  10. https://www.youtube.com/watch?v=YG6_xkAjeD4 ↩︎ ↩︎

  11. https://www.youtube.com/watch?v=0amclwspR0w ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  12. https://www.youtube.com/watch?v=I640OJ1gusE ↩︎

  13. https://www.youtube.com/watch?v=f8z4x6R7OSM ↩︎

  14. https://docs.godotengine.org/en/stable/tutorials/2d/2d_parallax.html ↩︎ ↩︎ ↩︎

  15. https://gdscript.com/solutions/godot-parallax-background/ ↩︎ ↩︎

  16. https://www.youtube.com/watch?v=2jq2chm9NuU ↩︎

  17. https://www.reddit.com/r/godot/comments/14gmqjf/is_there_a_way_to_make_an_automatically_moving/ ↩︎

  18. https://godotengine.org/asset-library/asset/1582 ↩︎

  19. https://docs.godotengine.org/en/3.4/getting_started/first_2d_game/06.heads_up_display.html ↩︎ ↩︎

  20. https://www.reddit.com/r/godot/comments/1eyplkj/best_practice_for_managing_game_scenes/ ↩︎

  21. https://www.youtube.com/watch?v=KQveZYmkwWI ↩︎

  22. https://www.youtube.com/watch?v=c5msTt9Jeyg ↩︎

  23. https://www.youtube.com/watch?v=g7c6EZzlDMA ↩︎

  24. https://www.reddit.com/r/godot/comments/12bjsnt/how_on_earth_do_i_properly_do_collisions_with/ ↩︎

  25. https://forum.godotengine.org/t/area2d-detecting-collisions-with-characterbody2d-but-not-staticbody2d/63493 ↩︎

  26. https://github.com/godot-addons/godot-object-pool ↩︎ ↩︎

Related

Make a Google Chrome T-Rex Style Side Scroller in Godot
Game Dev Godot Side Scroller 2d Tutorial
Madam Rides the Bus
9 mins
Madam Rides the Bus Class 10 English
Here is a summary of the chapter Madam Rides the Bus and answers to your questions, presented with ease of understanding and emojis, based on the provided sources …
The Proposal
5 mins
the Proposal Class 10 English
‘The Proposal’ is a short, one-act play by Anton Chekhov. It’s described as a farce. The story is about a marriage proposal between Ivan Lomov and Natalya Stepanovna …
A Glimpse Inside a Village in Chandauli, Uttar Pradesh
5 mins
Experiences Chandauli Unfiltered by Samdish Uttar Pardesh India
A House Is Not a Home
7 mins
A House Is Not a Home Class 9 English
Here’s a summary of A House Is Not a Home and answers to all the questions, presented for ease of understanding with emojis! …
A Legend of the Northland
8 mins
A Legend of the Northland Class 9 English
Here’s a summary of A Legend of the Northland and answers to all the questions, presented for ease of understanding …