0 votes

Hello!, I'm very new to Godot. I've been working on a project for a day or so just trying to get a feel for things. I come from gamemaker studio but its been a few years.

I'm making a very simple platformer. And I want the charcter sprite to have 1 sprite or animation when on the ground and a different animation if up against a wall or collision on the left a different one if collision on the right, and a different animation when jumping or in air or simply not colliding with anything so to speak.

My reason for this is i want there to be a small shadow on the sprite in the direction of a collision. Maybe there's a different way to do this than an animated sprite. With a shader or some other graphical option. I'm not sure but any advice or help would be greatly appreciated!

in Engine by (12 points)

1 Answer

0 votes

If you don't want to read the whole novel, the summary and images are at the bottom.

I would image this being made with a KinematicBody2D
This node has a function called is_on_floor()which returns true/false if the node is on the floor or not.
It also has another one which is called is_on_wall()which also returns a true/false value. The problem with this second one is, that we also need on which side the collision happened.
You can move the node with move_and_slide()and after it, you can get the collision data with get_slide_collision(). This function returns a KinematicCollision2D that has a property called normal which contains the collision's direction. This is a Vector2 type varialbe, so you need it's x value to determine on which side the collision happened.

TL;DR

Node setup
Node setup

Code on node
enter image description here

I wrote this in a hurry and didn't check if it's working. If it doesn't, let me know.

by (66 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.