Prev: https://eyeballtank.newgrounds.com/news/post/1331598
I wanted to add a pushable object that the Player and Companion could interact, by pushing it.
At first i used a RigidBody2D but had 2 issues:
- Every video i watched about pushing RigidBody2D's almost used the same "velocity = move_and_slide(parameters)" method and using that in a Player character script always messed with their values/physics (They jump higher and move faster than they should be); Because ideally, i'd want to access only one parameter which is the inertia part.
- The "pushable" object still felt floaty, even if it's just a matter of getting settings right.
So instead, i opted for a KinematicBody2D for the pushable object and even made copies of the Player, Companion and said Pushable object so i could use them as bases for new code.
And the stuff i did:
- Made a state machine on the player, including a PUSH state.
- Also put a state machine on the Pushable object, with "FROZEN" and "PUSHED" states.
- Once made it so that if the player touches the Pushable, they switch to a "state" with slow speed (Making the Pushable almost like a sludge hazard, since it works even when the player was on top).
- Gave the Pushable extra CollisionShape2D nodes based on up/down/both left and right sides, with a "left and side" collision being under a "pushableside" group (Then went back to one Collision).
- Used a RayCast2D on the player but it had like 3 problems:
- First was that it'd crash with things like the Tilemap or Area2D scenes because of specific code expecting another KinematicBody2D.
- Second being how it didn't flip properly (And even with code to flip, the angels were random as if it wasn't properly counting 360 degrees).
- Third being how the Raycast, no matter the size, would stop pushing the Pushable if the player was high enough in terms of placement.
So i deleted the Raycast node.
If you look at my code for the 3 scenes (Player, Companion, Pushable: Each with "Copy" after their names), you see a lot of commented code because i tried different methods.
I'm obviously committing the mistake of copying code from different tutorials and all, but it's because my coding skills are still weak.
The idea of using a RayCast2D came from a video by clecioespindolagamedev (Video titled "Como EMPURRAR e RESPAWNAR OBJETOS na Godot 3.4 (+Bug Fix Plataforma)") and the video even showed the pushable object as a KinematicBody2D.
Because i believe it's possible to make a pushable object (And pushing state for the player) work while using a KinematicBody2D instead of RigidBody2D.
A method i'm not even sure if i tried properly was make the PushableCopy detect collission from Player/Companion but only from its left/right sides and using inputs (Pressing "left/right") IF it's behind touched by those characters and from respective sides but the exact code reference is not in my head.
Again, my project can be seen here https://github.com/EyeBallTank/PROJECT-NORTUBEL-main-ish/commits/main
Even if you don't download it, you can see the updates and where the specific scenes are stored and their code.
As for other updates with my game:
- After the main menu, i got a somewhat working pause menu (Didn't made it a proper autoload scene, so it's part of the level technically).
- Got a jump pad scene that works.
- Added "placeholder" scenes like a soccer ball and ladder, that should be updated in the future (Even if i feel stuck in this Pushable situation because i made copies of the main characters, so i feel like i have to choose which versions of some scenes will stay so i can update them afterwards).
Guess the least i should do is focus more on learning Godot stuff.
Any help is appreciated.