Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How do I get smooth blast jumping in my game?

A topic by wyrmwiz created Aug 16, 2023 Views: 178 Replies: 9
Viewing posts 1 to 3
Submitted

I've gotten a significant way on working on what is essentially a simplified, TF2 clone that will probably be more explained at a later time but right now I've gotten into a bit of trouble figuring out how to get buttery acceleration and deceleration since I made a different type of character controller than the ones provided in this jam but it should work fine for what I am trying to go for. The explosion blast knockback is too choppy for my liking and is pretty inconsistent. The blast jumps technically "work" but you aren't able to really replicate them or chain them which is something I definitely want for my game. I used some code from looking at what other rocket jump game's people have made in Godot and here's what my code looks like: 

--------------------------------------------------------------------------------------------

func _on_Area_body_entered(body):

var vector = body.global_transform.origin - global_transform.origin

var direction = vector.normalized()

var distance_squared = vector.length_squared()

var speed = 100

var velocity = direction * speed/distance_squared

var damage = 50

if body is Player:

body.velocity += velocity

body.health -= damage

--------------------------------------------------------------------------------------------

So what this basically does is launch the player's collision away from the collision of the explosion radius but it's not always as strong as it should and sometimes it's too weak or it doesn't even go in the right direction. I could probably write this off as finnicky accuracies and Godot's collision quirks, but what happens is a immediately burst of speed into a direction but there's no smooth slowing down gradually that is the problem. There's this game called "Neon Utopia" that replicates rocket jumping well enough but I don't have the ability to see how it's done and the project hasn't been updated in a while. Anyone working on a game that has figured this out?

HostSubmitted

"there's no smooth slowing down gradually"

If that's the case, maybe the problem you are facing isn't with the explosion jumping part of the code. From what I can tell, the explosion jumping part does what it is intended to do: it adds velocity to the player based on an explosive radius.

How are you handling the code that stops the player, when he is in motion? Like, the basic movement code. Maybe that's where you have to check to find your problem. If you are moving with code like this: 


If W pressed -> velocity = 1.0

If W not pressed -> velocity = 0.0


Then your character does not have any momentum, meaning you haven't coded any way to naturally slow down, it is only based on key inputs. Maybe that's why you don't slow down after an explosion jump, that's my guess.

Submitted(+1)

So I figured it out and it kind of happened in an instant of mad science magic so I don't know how to properly document it so I'll write my thoughts down as quickly as possible.
It was honestly dumb luck that I started multiplying and dividing things and I made this new variable called "move_multiplier" which I divided by the equation used to calculate velocity:

velocity = velocity.linear_interpolate(direction * speed, accel * delta * move_multiplier) / 1.0025

The "1.0025" is what I like to call, "the slog constant" or basically how dampened the movement is for the player. If divided by a small number under 1, it will accelerate the player in a way I do not like while they are in motion. If they are in motion though, this constant makes it so that they will start moving and then reach a max and then stop. I decided to add the move_multiplier first as a way to slow the player when they stopped moving as you suggested but then I gave it a less than 1 value and saw that it added what I can only describe as a "slippery factor" where they would glide off of surfaces and then stop. The movement was a bit too tight than I would have liked it to be and there was no momentum so I thought this was a cool addition. The problem was that this was only affective on floors so what I did was make another variable (which I already had for other reasons but decided to repurpose) called IsAirborne. IsAirborne is a boolean that uses is_on_floor as it's indicator. So what I did was this:

(This is in the _physics_process(delta) function by the way)

if IsAirborne == true:

move_multiplier -= delta

move_multiplier = clamp(move_multiplier, .05 ,.8)


if IsAirborne == false:

move_multiplier += delta

move_multiplier = clamp(move_multiplier, .05 ,.8)

Delta basically keeps account the time passed since the condition is met so the more a player is airborne they will experience a clamp (min and max range) that reduces the value move_multiplier (where small values make the movement more slippery) and in reverse, if the player was not airborne, they would experience less slippery, more grounded movement. I like to think about these values as the "grounded range" that controls how tight the movement is, where move_multiplier is made to go toward .05 (very slippery) when airborne and then on the ground will go to .8 (very tight but some slip for general movement consistency).

I probably inadvertently recreated something someone else already did and it broke part of my auto-bhop functionality but I'll plan to see if I can fix it somehow but right now I'm satisfied I concocted this weird but workable movement system.

I'll go more in depth if you want but I already rambled a lot and I frankly don't know how I even figured it out.

HostSubmitted

Nice! I'm glad you got it sorted out!

(2 edits) (+1)

Bit late to this and you probably got something good working now but I'm actually that guy who made Neon Utopia and yea I probably spent years trying to get a rocket jump mechanic as close to TF2 as possible (while also trying to keep the code simple) and it got to the point where I could even perform all the tech like speed shots or bounces

Sadly the project died due to Godot 4 having a new physics engine that broke surfing and some other things like the global illumination having terrible performance for me but worst of all even some newer versions of Godot 3.x were starting to break my project and I went from adding features near daily to basically never

So I had no choice but to quit but I may end up dumping the project on GitHub someday if you or anyone is curious how my code worked but feel free to add me on discord (imh_turtle) if you wanna talk about it some more and I can possibly even share and explain some of my code better there

Also hopefully I may end up reviving the project with all the knowledge I gained on how voxel rendering works without using meshes like Minecraft and now there's no need to worry about physics breaking or other things exploding on me cause it's all my own code and I even got this to where I now have my own mini engine for this and it's cool just how portable the code is since it's all shader magic so it'll work in any game engine

HostSubmitted

I also stopped what I was doing because of the godot 4 update. I have to get back at it sometime in the future.

Submitted

First of all, I got to say I really liked your game. There is another rocket jumping game that some guy is making in Unity that I am following so hopefully that will go somewhere...

I would be really glad to see your code and maybe I can give you a sneak peak as to what I already have because since I've originally posted here I've made a ton of progress but I wasn't going to show it until later when it was really refined to my liking. 

As for the Godot thing, it does suck that your project broke and I might heed your advice and transfer the project to an LTC version of Godot so that it can last but it might be too late for that or maybe it's still possible, who knows...? To hear you actually went ahead and programmed your own mini-engine is fascinating and sounds really difficult to make sure everything in the 3D world works.

One problem though is that I don't use Discord for personal reasons so it will have to be somewhere else. I have a Revolt (Discord-like) but if maybe we can talk here or find some other platform.

I hope I am not late in replying to this but anything helps.

(1 edit)

Oh hey glad to see you reply late or not and yea I totally understand not using Discord seeing how scummy it's getting and I've actually been looking for an alternative for a while now so I'll have to give Revolt a try

I'm also curious to see how your project has been going and I'm curious on that rocket jump game being made in unity as well

But yea I'd love to share my code since it's already on GitHub just private currently and I was just waiting until I finished the game or people showed enough interest in it

Also when it comes to using Godot 4 or not I feel like it's still worth the risk even if some things break and I actually have another friend who seems to have fixed the surfing issue on the new physics engine and hopefully he'll share the code for that eventually

Oh yea and you'd be right about the 3D engine being quite difficult to get things working but so far it's been going quite smoothly and hopefully I'll actually make some neat things with it

(Edit) Just tried Revolt and yea it's super nice so if you wanna add me there my tag is Turtle#2234

Submitted

Got it. I cannot talk to you this weekend but expect me to reach out next week or so. I am very excited to talk to you and show you what I've been working on but it's just a bit of awkward timing because of the end of the year chaos. 

Yea that's totally understandable and I yea I've been quite busy irl myself so I'll see ya then