Open laifrank2002 opened 5 years ago
I mean, we're going to adjust a bunch of constants. That's all that we need to do. I think. Maybe I'm wrong...
I think it's one of the radius ones? Still, something's wrong with our restitution formula because that force is too darn big... divide by 0 possibly?
It's our constants. Right now, Player.prototype.deceleration
is a very small number. This means that when a player gets pushed really hard (such as when they destroy an asteroid), it takes them a long time to slow down.
Also, the main reason why destroying an asteroid is so forceful is because it creates two smaller asteroids, each of which could be spawned inside the player.
If there was a divide by zero issue here, then the collision detection algorithm would spit out NaN
for the player's coordinates. I had this problem when I tried to make projectiles push the player. The projectile was created exactly where the player was, causing the distance to be zero and the player's coordinates to be set to NaN
. I still don't understand how it happened, so the best thing is to avoid that problem altogether (weapons.js
is my answer). The point is that it's not a divide by zero problem.
Still going on in the new overhauled version. Can't we fix the restitution formula then, so then instead of changing velocity we just change position? Could be just a check in asteroid spawning.
Changing only the position for collision detection means that when you knock back an asteroid, the asteroid jitters back, but keeps going in the same direction, as if nothing happened.
The only way to truly fix this would be to factor in the weight of the ships and asteroids (and also momentum, inertia, and force). This would be a true physics engine, and would be pretty complicated to pull off correctly as everything would have to be updated (again).
Since that's only going to happen once (because that only happens during collision itself) then it shouldn't affect performance too much. We ought to create a physics engine, or borrow one.
I mean, how often does it happen now? If it rarely happens, we can just ignore it.
Well, once a session for me, so... it's likely every player will encounter the bug at least once in their lives. Can't we just... if there's a player there, spawn the asteroid 25 px somewhere else?
When you pilot your ship near an asteroid that it physically touches it, and then destroy it, you get propelled like half the map backwards.