|
|
|
 |
Attention |
Topic was automatically imported from the old Question2Answer platform. |
 |
Asked By |
Matthewblakk |
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!
|
|
|
 |
Reply From: |
Fenderbate |
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

Code on node

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