Skip to content
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

Merged
merged 16 commits into from
Apr 12, 2024

Conversation

DarkStoorM
Copy link
Contributor

@DarkStoorM DarkStoorM commented Apr 2, 2024

🤸‍♂️ 💨

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, with R60 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):

img

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...)

  • 0dc3cc0 We had an unused SetColor method, maybe it was some old stuff, no idea. It was changing the sprite color
  • I noticed there was a condition that was never used with the other stuckInAir 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 to Land when touching the floor 🤔 this also resulted in removing the _wasOnFloor, which was the only occurrence
  • code in _PhysicsProcess was extracted / grouped similarly to what I do in the new code
  • reordered methods - I like having built-ins first (if possible) and using _Ready for caching components

The RandomJump was also never used anywhere, so I added a hotkey J that takes all active jumpers and makes them jump in random direction. Useful for testing jumps on the bots you add with B key. Launch the game, press B, hold J

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 like declare inside TypeScript classes where you expose props, but initialize later.


Video:

cartwheels.mp4

@DarkStoorM DarkStoorM mentioned this pull request Apr 2, 2024

public override void _Ready()
{
_animatedSprite2D = GetNode<AnimatedSprite2D>(SpriteNodeName);
Copy link
Owner

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. 😢

Copy link
Contributor Author

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.

@AdamLearns
Copy link
Owner

While this looks good and I would merge it, I would vote for putting this behind an opt-in command like spin on|off. I'll see what people on Discord say though (poll link).

@DarkStoorM
Copy link
Contributor Author

DarkStoorM commented Apr 11, 2024

While this looks good and I would merge it, I would vote for putting this behind an opt-in command like spin on|off. I'll see what people on Discord say though (poll link).

Speaking of poll, I personally would be going with default on, but actually, now I see there are more options:

  • off, opt-in - everyone (command toggle)
  • always on - everyone (no command toggle)
  • always on - subscribers only (no command toggle)
  • off, opt-in - subscribers only (command toggle)

But maybe this could just be another Subscriber feature that works just like glow for example 🤔

@Adam13531
Copy link

Adam13531 commented Apr 12, 2024

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. 🤦‍♂️

@AdamLearns AdamLearns merged commit 8142ea6 into AdamLearns:main Apr 12, 2024
2 checks passed
@DarkStoorM DarkStoorM deleted the add-jumper-spin branch April 13, 2024 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants