« first day    last day (16 days later) » 

12:00 AM
I'm trying to make it as much realistic as possible
you even said the other approach would be harder to handle collisions
 
For a 2D roguelike, that's probably not an ideal goal to choose.
I also showed you a solution to the knockback problem.
Using forces doesn't strictly make that easier, it just changes the kinds of problems you need to solve, and the tools you have to solve them.
 
you said we could calculate such a force from max speed and time, how do we do this?
 
To do this, we need your friction model, since it will affect when you hit your max speed.
That is, unless you're achieving your max speed by clamping.
Let's try that version first. It's a bit crude, but it'll at least give us a starting point.
Let's say we start at a standstill, and accelerate at our maximum force in one direction for t seconds until we hit our max speed, with no friction slowing us down:

maxSpeed = 0 + acceleration * timeToMaxSpeed
maxSpeed = (controlForceMagnitude/mass) * timeToMaxSpeed
maxSpeed/timeToMaxSpeed = controlForceMagnitude/mass
mass * maxSpeed/timeToMaxSpeed = controlForceMagnitude
 
12:15 AM
which ends up as acceleration = inputDirection * (mass * maxSpeed/timeToMaxSpeed) / mass
 
Yep. Note how mass cancels out there?
 
yea
 
If you want higher mass to make characters accelerate more sluggishly, you'll want to use one mass for calculating controlForceMagnitude (call it a standard reference mass), and then use the character's actual mass for the division.
 
but didnt the masses just cancel?
ohhhhhhhhhhh
I mean
 
I'm describing what you would do to make them not cancel.
 
12:20 AM
I dont get it
 
So it could be
acceleration = inputVector * (maxSpeed/timeToMaxSpeed) * (standardMass/mass)
 
oh
 
For characters that have your standard mass, these two will still cancel out, and they'll reach their max speed in exactly the time you set. For a character twice as heavy as the standard mass, they'll take twice as long to hit their max speed.
 
what is a standard mass though?
ughhhhhhh
 
It's a tuning value. It says "This is how heavy I expect my usual character to be"
Don't try to get rid of all your tuning values. Game design is about choices. You can't just abdicate every decision and calculate it from some physics constant of the universe. You're making your own universe, so you need to supply the constants. :)
 
12:25 AM
this is slightly more confusing than the other approach
what about if we...
use the weight force?
if I'm getting it, this might be much easier and realistic
weight = mass * gravity
we can define a gravity value for our world
we can even remove gravity at some point of the game!
and then we could have accel += (weightForce * input) / mass
does this make any sense?
 
Note how your masses cancel again.
So you've just arbitrarily decided that all characters - of any mass - should propel themselves around at 9.81 m/s^2.
This is a valid choice, but it's no less arbitrary than any other value you could assign to a controlAcceleration or controlForce parameter.
 
your last approach requires 3 variables in order to find a force: max speed, time to max speed and "standard mass"
 
That's why I offered you a single one, controlForceMagnitude, as a simpler starting point.
 
yea, the problem is that id need to test each value for each different mass
 
Welcome to game design. ;)
 
12:37 AM
im getting confused all over again
but ok, we have acceleration += inputDirection * controlForceMagnitude / mass
lets just leave controlForceMagnitue alone
did we just apply "thrust" here?
 
Yes.
 
btw thrust and impulse both means the same thing in portuguese, so I have no idea what thrust really is
but whatever
next question: what if we're running? how would the formula be?
 
Basically the same thing.
 
we accelerate faster when were running, no?
 
Yep, so you'd use a greater input parameter.
 
12:44 AM
you mean controlForceMagnitude?
 
Yep. You'd have something like walkingForce and runningForce
 
so if were walking, we have accel += inputDirection * walkingForce / mass;
if were running, we have accel += inputDirection * runningForce / mass;
 
Something like that.
 
is deceleration considered a force?
it is, right?
since deceleration is just an acceleration to the opposing velocity direction
 
1:03 AM
A force is an acceleration or deceleration times a mass.
To get from a force to a deceleration, you need to divide by mass.
 

« first day    last day (16 days later) »