How to Make Sans’s Battle from Undertale in Scratch ep.1

How to Make Sans’s Battle from Undertale in Scratch ep.1
ok-scratch
We’ll be creating a battle from Undertale. Let’s focus on one of the fan-favorites: the Sans battle! In the later parts of this series, we’ll even take on implementing the Gaster Blaster. But first, let’s start by building the basic movements together.
Starter
Projects
Starter Project
Sample
none
Difficulty
Tags

Make sure to jot down the URL of your Scratch project in progress. It’s a lifesaver when you’re ready to dive back in.

LOADING...

This record is saved on the computer you’re currently using. So, if you switch to a different computer, you won’t see it there.

Let’s dive into the world of Undertale in Scratch! We won’t recreate the entire game, but we’ll build a program that captures the unique feel of Undertale. You’ll get a taste of the underground monster world and experience the excitement of choices that shape the story. Add your own ideas to make this adventure uniquely yours!

In this tutorial, we’ll focus on battling Undertale’s popular character, Sans! We’ll recreate some of his unique attacks and fast-paced battle style to give you an original experience in Scratch. Get ready for the thrill and challenge of facing Sans—let’s have fun and see if you can keep up!

Remix

This project comes with a starter project ready for remixing. Download the file and load it in the Scratch editor. Inside, you’ll find costumes ready to use!

ok-scratch ok-scratch

The Sans and Gaster Blaster costumes in the starter project were remixed from inkdemon888's work. Thank you!

Soul

Let's start by coding the Soul!

When the green flag is clicked, set the X and Y positions to zero.

Go to back layer.

Variable 'GRAVITY'

Create a new variable named 'GRAVITY' for all sprites.

Initialize this variable to 1.

Variable 'HP'

Create another variable named 'HP' for all sprites.

Initialize this variable to 10000, or less, as you like.

Place the forever block.

Place the 'if - else -' block inside the loop.

Block Definition 'Red Movement' and 'Blue Movement'

Create 2 new block definitions for the player movement.

Put each of these blocks inside the matching condition.

Place another 'if' block below.

Insert 'touching color?' block into the condition and adjust its settings.

  • Color 100
  • Saturation 0
  • Brightness 100

Change HP by -1 inside.

Block Definition 'Red Movement'

In this block definition, we’ll set up controls for when the Soul is red. The red Soul can move freely in any direction without gravity. However, it can't leave the white border, so we’ll need to add some boundaries.

Swith costume to red first.

Create 2 new block definitions

Use these blocks here.

Block Definition 'Move X'

In "Move X," we'll set up controls for horizontal movement.

Place 'if' block and insert 'key right arrow pressed?' into the condition.

Chage X by 5 inside.

Surround this with a 'if' block.

Preview the screen to check the x position for the sides of the white border.

Since the X coordinate is 90, make a condition to check if the x position is less than 90.

Duplicate all the blocks we've created in "Move X" so far.

Place them right below.

Make the necessary adjustments throughout.

Duplicate all the blocks again and place them in 'Move Y'.

And here, make any necessary adjustments as well.

Check the y position of the top and bottom white lines in the preview screen.

For me, the top was 65 and the bottom was -115, so I'll adjust the conditions to match these values.

Preview

Before testing, fix the value of 'GRAVITY' to 0, which means there are no gravity.

Test it!

Perfect! Now we can move freely within the square! Yes!

Block Definition 'Blue Movement'

When the Soul is blue, gravity is applied, so unlike the red Soul, it can’t move freely within the border. Instead, it's in a mode where it can only move vertically by jumping, just like in typical platformer games.

Switch costume to blue and Move X first.

Create 2 new block definitions

Use these right below.

Variable 'SPEED Y'

Create a new variable named 'SPEED Y' for all sprites.

Block Definition 'Jump'

Place an 'if' block and check 'key up arrow pressed?'.

Set "SPEED Y" to 8. Feel free to change this value! If you want to jump higher, increase the number; if you want a lower jump, decrease it.

Place an 'if' block and insert the expression 'y position > 65' inside.

Set 'SPEED Y' to 0.

Block Definition 'Gravity'

Change y by 'SPEED Y'.

Insert the expression 'y position < -115' into the condition.

Change y by '0 - SPEED Y' inside.

Set y to -115 right below.

Set 'SPEED Y' to 0.

Change 'SPEED Y' by -2 out of the 'if' block.

Preview

Alright, it's testing time!

Right-click "GRAVITY" in the preview and select 'slider'.

Right-click it again and select 'change slider range'.

Set its max value to 1.

Smash the green flag!

Cool! We successfully implemented the gravity mode! Woo-hoo!

That’s it for now! Player movement is complete. We’ve added a unique Undertale feature where the controls change between the red and blue Souls, unlike a typical platformer. Next time, we’ll dive into coding Sans’s attacks. Get ready to dodge incoming bone attacks with the movement controls we set up today! Stay tuned for an exciting gameplay experience!

Thank you for reading! Thank you for reading!
Bookmark and share this article, if you like.

Scratch Games

    • You can find popular scratch projects with reviews.