Hey All,
This is my first question on the forum so sorry if I don’t provide enough information (I post a lot on stack exchange so I will just do what I would do there).
I am currently trying to make a rigid body player movement system using forces. Since doing this will allow me to update the mass of the player (if they are carrying more or less equipment), have different drag values on different surfaces (If you are on ice or concrete movement would be different), and have a modifier on the default force amount (so if I implement a skill system where a skill would make you move faster I would just add a multiplier to the default force). I originally started by trying to implement a clamp on the velocity of the player but this isn’t needed when you have drag and weight will only allow a maximum movement speed by default. The issue I am currently running into is when adding force in the forward direction (lets say the maximum magnitude with my set weight/drag is 3 when moving forward) and in the sideways direction (lets say the maximum magnitude with my set weight/drag is 1.5 when moving left/right) but the total magnitude is actually much higher than I would want. So if you hold the “w” and “a” key at the same time then look a little to the right so you are moving diagonally towards you where you want to go you are actually moving FASTER than if you are just pointing directly at the location and holding “w”. I was trying to think of a way to get around this but I don’t have a good enough understanding of the physics system to accomplish my goal. Here is a snippet of my code below so you can see what I am doing (I have different states for each standing/proning/crouching so I cut out some of the code to make it quicker to read):
void move_forward()
{
switch (movement_standing_state)
{
case movement_standing_states.prone:
switch (movement_speed_state)
{
case movement_speed_states.slow:
move_player(local_player_rb.transform.forward, slow_prone_forward_force);
break;
case movement_speed_states.normal:
move_player(local_player_rb.transform.forward, normal_prone_forward_force);
break;
case movement_speed_states.fast:
move_player(local_player_rb.transform.forward, fast_prone_forward_force);
break;
}
break;
Coupled with a move left function:
void move_left()
{
switch (movement_standing_state)
{
case movement_standing_states.prone:
switch (movement_speed_state)
{
case movement_speed_states.slow:
move_player(-local_player_rb.transform.right, slow_prone_sideways_force);
break;
case movement_speed_states.normal:
move_player(-local_player_rb.transform.right, normal_prone_sideways_force);
break;
case movement_speed_states.fast:
move_player(-local_player_rb.transform.right, fast_prone_sideways_force);
break;
}
break;
And the actual add force function:
void move_player(Vector3 direction, float force)
{
local_player_rb.AddForce(direction * force);
}
Thank you for any help ahead of time!