Im using rapier in my tiny bevy project, I have a mechanic similar to rocket jumping where an "explosion" is created wherever I right click and if i am close enough I will be forced away from it. I am having issues making that work with the movement through wasd
#Help With Physics Based Movement
23 messages · Page 1 of 1 (latest)
when I hold any movement key I just end up accelerating forever since I am adding onto my linear velocity where as before I was just setting it before i set up the rocket jumping, I have tried messing around with damping but not to much avail so im curious about how someone would go about fixing that while keeping the rocket jumping mechanic intact
you could try an impulse
i tried using that instead of modifyling the linear velocity but the impulse still changes the linear velocity leading to the same issue
you could try adding your own drag force instead of using linear damping.
something like:
let drag_force = drag.0 * velocity.linvel.length();
velocity.linvel *= (1.0 - drag_force * delta_time).max(0.0);
or
drag_force = constant * velocity^2
i will try setting that up when i am back home. thank you!
i tried that however the problem is still pretty much the same
i feel like i did a weird job at describing what my problem was so i took a video of it
before i added the rocket jumping esque thing i was just setting the linear velocity equal to the movement vector i had used for getting the input from the wasd keys
but that made it so i couldnt really get blown back because every frame i was setting the velocity to 0 or some rigid number like 5 with the movement code, but i cant really figure out how to do it any other way without making just an infinite acceleration kind of thing whenever i hold a key
because i am still somehow adding stuff to the linear velocity every frame and im not sure how to take the rotation of the camera into account every frame and adjust the speed accordingly without making my character accelerate infinitely
i could just fix that by setting the damping higher however that makes it so the speed at which I get blown away from the rocket is much slower too unless i am just setting that up wrong
first, you probably want to normalize your directional input otherwise your diagonal vectors will be longer than cardinal left/right/up/down.
oh and you're using the cam's relative axes to add to velocity.
Just turn your 4 directions into a single normalized Vec2 and then set your impulse = to that * speed
thats a good idea lol i didnt think about that
also i didnt include the rest of it but i do normalize them further down before i apply them as impulses
here is the whole repository, its extremely messy and horrible so sorry about that 😨 https://github.com/GabeeeM/bevy-fps-test
GitHub
Contribute to GabeeeM/bevy-fps-test development by creating an account on GitHub.
right now i just went back to the linear velocity thing but i trieed impulses and the result was the same, is it like a better practice to use impulses rather than setting the linear velocity directly?