HELP with my mailman

Godot Version

4.5.1

Question

So i have a problem with scripting and everything so i made a village in my game and wanted to have a mailman, he had to have a schedule (i have a time system in my game) and he had to deliver mails to every mailbox; i tried different things but tey didn’t work, he also has animation for walking and when he is beside a mailbox an animation plays throw mail (i have one for left and one for right), i’ve been stuck on this for a few times now so i doon’t know what to do and what i’ve done wrong here is my mail man. I also can’t seem to make the mail visible, when i turn visible it’s always visible so please help me

I’m not sure I or anybody else can help you with your problem. I have no idea what your problem is,

I would suggest you take a bit more time to formulate what your actual problem is, what you have tried, what code you currently have, and what the end goal should look like. Only then is it actually possible to begin to help you.

Start with a specific issue, because this is waaaayy too broad

4 Likes

Godot Version

Question

I have a mail man with walking animation (left, right, down, up) and idk how to animate them since its an npc… i also have some other animations for my mail man such as throw mail right and left i want my mail man to play these animations when he enter the hurt box of the mailboxes (it’s okay if you only can help me on the first part i know the second one is kinda hard to understand sorry english is not my first language)

Hello again, from you last picture it looked like you were trying to animate the mailman using a sprite2d for the mailman, right?

The best way to do this (in my opinion) is to use the AnimatedSprite2D node together with an AnimationPlayer node (if you have a sprite sheet)

I think this video explains it well :slight_smile:

For the part about the mailman throwing the mail. You should add a “throw_mail” animation just like adding the walk animation.

Then in your village scene i would create a node setup like this :
image

Where the collisionshapes are squares that are in front of the villagers mail boxes

And connect the signal _on_body_entered(Body : Node2D) to the mail_man_script and add some code that looks something like this:

func _ready() -> void:
        add_to_group("mail_man")

func _on_area_2d_2_body_entered(body: Node2D) -> void:
	if body.is_in_group("mail_man"): # create a group and add 
       print("mail man is standing in front of house")
        # and then play your throw mail animation here

What this node setup and script does, is that it sees when the mail man is in front of the mail box and then tells the mail man to play the throw mail animation

It is possible to make this code more complete (this would also make it more complicated - but it could be a good learning experience :slight_smile: )

I hope this helps :slight_smile:
Please dont hesitate to ask if you have any questions (I’m not very good at explaining things)

hey so it helped me but it’s just that my throwing mail animation need to be flipped because i only have frame for one side, and i can’t figure out how to flip h with animated sprites. Also the tutorial you gave me is for a player so idk what to change to fit into an npc, because i don’t control my npc

I believe you would check what direction the mailman is facing and then from script depending on his direction you either set flip_h as true or false.

You don’t control the mailman directly no, but you do get to decide how he moves around. I think you should be able to do

if velocity.length >= 0.01: # check if velocity (player is moving)
animated_sprite.play("walk")
else:
animated_sprite.play("idle")

To flip the animation you just do as in the video
But also this depends on how the mailman throws the paper. If you decide which direction it is or if its random

if direction == 1
animated_sprite.flip_h = true
else: 
animated_sprite.flip_h = false