Brackey's "How to make a Video Game - Godot Beginner Tutorial" Question?

Godot Version

4.2.2

Question

Hello All,

As the title suggests I am going through the new Brackey’s Tutorial on Godot and have run into a problem in the Lesson titled: “How to make a Video Game - Godot Beginner Tutorial” on his YouTube channel.

The new tutorial introduces an enemy, but, the enemy is just floating in the tutorial and is not affected by gravity and this would not do for me. So, I changed it into a character used the default script and made some changes so it would not be affected by the use of the keyboard and disabled the jumping, but, something strange happened, the enemy fell down a platform, went to the one below all as expected and then went through a coin (Mario style) and “collected it”. So, the question is this, how would I stop the “enemy” colliding with the coin and stop it from “collecting” them. The “coin_collect” script only tests for a collision with any “body” making contact with it, whereas, now I need to stop the enemy going by having it go completely through it and having only the “hero” collecting it. I know the body has an “id” for describing what hit it, I found that out by printing the body for debugging purposes, but, does that help in any way? I can’t figure out how I would do this.

As always any help is greatly appreciated.

Thankyou and Regards.

Yes, you have to check if the body is the player character somehow. On way to do it is to add a player character to a group called “player” or “hero” as you called it, doesn’t matter. Then check if the body is in sad group:

if body.is_in_group("player"):
#pick up coin
4 Likes

Can I ask a question here too please? I’m also working on Brackey’s beginner tutorial and I’m using a Mac.
Several things seem different on the Mac and I’ve spent quite a bit of time working out the differences.

  1. When I created the Nodes and then set the physics collision shapes (CharacterBody2D) and then CollisionShape2D with the CircleShape2D - the little warning alert would not go away until I saved and then restarted Godot 3 times.

  2. Creating the “New WorldBoundaryShape2D” - the knight kept falling through the collision shape until I turned it upside down compared to how Brackeys shows on his Windows version of Godot.

So the questions are - is Godot meant to be the same across Mac and PC? If not - and I create games on a Mac, will they work differently on a PC?

And… are there lots of inconsistencies between the Mac and PC versions?

Never used a “group”. I’ll look into it,

Thanks greatly.

PS: After a quick look into creating groups I set one up and success :joy:. Thanks so much.

1 Like

I sometimes have a similar issue when I have to to reload the project when I change a script and other scripts don’t see the changes until I reload. But I’m on linux not mac.

I doubt WorldBoundaryShape2D is supposed to work differently on different platforms, but you should probably start a new thread about differences between mac and other versions to get the people’s attention who might be able to answer.

1 Like

extends CharacterBody2D

const SPEED = 100.0
const JUMP_VELOCITY = -200.0

@onready var animated_sprite = $AnimatedSprite2D

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)

func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta

# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = JUMP_VELOCITY


var direction = Input.get_axis("move_left", "move_right")

if direction > 0:
	animated_sprite.flip_h = false
elif direction < 0:
	animated_sprite.flip_h = true

if direction:
	velocity.x = direction * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)

I’m using Brackeys Code of Godot tutorial but he sprite is not flip horizontally is there something wrong with it please let me know any help will be appreciated

I think it needs to be direction.x

if direction.x > 0:
	animated_sprite.flip_h = false
elif direction.x < 0:
	animated_sprite.flip_h = true