-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add jumper spin, rewrite some logic #92
Conversation
This method had no references, I don't know what was the origin of this, probably some early Jumper color overlay(?)
Rather than accessing the nodes all the time through GetNode, just cache them once on _Ready and reuse. This also changes when the player-specific Setters are fired, because when we call Init on join, the node has not really entered the tree yet, so the components were not ready to use.
|
||
public override void _Ready() | ||
{ | ||
_animatedSprite2D = GetNode<AnimatedSprite2D>(SpriteNodeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GDScript has @onready
for this (reference), so I was hoping to be able to point you to the equivalent in C#, but apparently it still doesn't exist. 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's why I use this inside Ready until they implement it (without relying on 3rd party libraries), I also do this in Unity: initialize (cache) components once they enter the scene (Awake() in Unity or entering the Tree in Godot). This throws an exception if the component does not exist, so in my opinion this is a good enough solution, unless there is an actual proper way of doing this.
While this looks good and I would merge it, I would vote for putting this behind an opt-in command like |
Speaking of poll, I personally would be going with default
But maybe this could just be another Subscriber feature that works just like glow for example 🤔 |
We can see what people say with feedback. Allowing people to opt out may be fine. I'll merge this for now—thanks! 🙏 EDIT: couldn't find a merge button, then realized that even this comment was made from the wrong account. 🤦♂️ |
🤸♂️ 💨
This PR adds the sprite rotation whenever we jump at a non-zero angle. I didn't want it to rotate at constant speed, but to increase non-linearly based on the X velocity, so assuming we jump at full power with
R5
, we will rotate slowly, withR60
we hit the cap to not make the jumpers spin super fast. The formula is in the code, but the general idea:Maximum velocity of a
R90
jump is 700, but we rarely even go above 60-70°, so I went with a limit of 600. I made up some random formula that outputs a multiplier of 1-7 applied to the base rotation value (x: Velocity / y: Multiplier):The extra formula wasn't really necessary, but I wanted it to rotate slowly up to like 15°
Other stuff:
(I forgot I was supposed to separate the following, but well...)
SetColor
method, maybe it was some old stuff, no idea. It was changing the sprite colorstuckInAir
condition (justLanded
), removing it didn't even change anything - maybe I don't know the context of that, but the animation is still switching correctly toLand
when touching the floor 🤔 this also resulted in removing the_wasOnFloor
, which was the only occurrence_PhysicsProcess
was extracted / grouped similarly to what I do in the new code_Ready
for caching componentsThe
RandomJump
was also never used anywhere, so I added a hotkeyJ
that takes all active jumpers and makes them jump in random direction. Useful for testing jumps on thebots
you add withB
key. Launch the game, pressB
, holdJ
Note
Note on
null!
component declaration: you can't access nodes through constructor, only when they enter the tree, so they have to be accessed through_Ready
, which produces a warning, hence the null forgiving operator to indicate that fields are initialized at runtime and you are 100% sure they won't be null before they are used, which doesn't require declaring as nullable and performing null checks everywhere. Kind of likedeclare
inside TypeScript classes where you expose props, but initialize later.Video:
cartwheels.mp4