1bytecharhaterxxx
New member
- Joined
- Jan 17, 2021
- Messages
- 8
i'm really getting mad to implement a movement system on my engine,i really need to help to understand how this is usually done cause i'm a beginner what i've done so far is this :
//////+Z UP///-Y FRONT////-X RIGHT
//////FRONT_BACK
VEC3 delta_front,delta_right,delta_y,delta_x,delta_xy;
core_ptr->mov->delta_accel = RUN_ACCEL * core_ptr->timer->delta_t;
core_ptr->mov->delta_friction = pow(RUN_FRICTION,core_ptr->timer->delta_t);
///////////FRONT
vec3_quat_multiply(delta_front,core_ptr->cam->inv_orientation,FRONT_VEC);
vec3_scale(delta_y,delta_front,core_ptr->mov->y_vel);
//////////////////RIGHT
vec3_quat_multiply(delta_right,core_ptr->cam->inv_orientation,RIGHT_VEC);
vec3_scale(delta_x,delta_right,core_ptr->mov->x_vel);
delta_xy[0] = delta_y[0] + delta_x[0];
delta_xy[1] = delta_y[1] + delta_x[1];
core_ptr->cam->cam_pos[0] += delta_xy[0];
core_ptr->cam->cam_pos[1] += delta_xy[1];
if((key_is_pressed(core_ptr,core_ptr->kbd->move_front)) == 1 )
{
core_ptr->mov->y_vel -= core_ptr->mov->delta_accel;
}
if((key_is_pressed(core_ptr,core_ptr->kbd->move_back)) == 1 )
{
core_ptr->mov->y_vel += core_ptr->mov->delta_accel;
}
if((key_is_pressed(core_ptr,core_ptr->kbd->move_right)) == 1 )
{
core_ptr->mov->x_vel -= core_ptr->mov->delta_accel;
}
if((key_is_pressed(core_ptr,core_ptr->kbd->move_left)) == 1 )
{
core_ptr->mov->x_vel += core_ptr->mov->delta_accel;
}
core_ptr->mov->x_vel *= core_ptr->mov->delta_friction;
core_ptr->mov->y_vel *= core_ptr->mov->delta_friction;
printf("X VELOCITY = %lf\n",core_ptr->mov->x_vel );
printf("y VELOCITY = %lf\n",core_ptr->mov->y_vel );
So,basically this is working,the problem i'm facing btw is that when i press for example front+right,the speed is a lot higher cause it sums the 2 velocities,so i have double max speed and double accel...i really want to keep updating the positions togheter to let the friction always kickin in,but i didnt find any easy solution to this problem,ideally i would have only a single velocity,and i would update the 2 vectors accordinly but i have no idea i'm just lost...i hope someone is so gentle to help me with the math theory :/ bye
//////+Z UP///-Y FRONT////-X RIGHT
//////FRONT_BACK
VEC3 delta_front,delta_right,delta_y,delta_x,delta_xy;
core_ptr->mov->delta_accel = RUN_ACCEL * core_ptr->timer->delta_t;
core_ptr->mov->delta_friction = pow(RUN_FRICTION,core_ptr->timer->delta_t);
///////////FRONT
vec3_quat_multiply(delta_front,core_ptr->cam->inv_orientation,FRONT_VEC);
vec3_scale(delta_y,delta_front,core_ptr->mov->y_vel);
//////////////////RIGHT
vec3_quat_multiply(delta_right,core_ptr->cam->inv_orientation,RIGHT_VEC);
vec3_scale(delta_x,delta_right,core_ptr->mov->x_vel);
delta_xy[0] = delta_y[0] + delta_x[0];
delta_xy[1] = delta_y[1] + delta_x[1];
core_ptr->cam->cam_pos[0] += delta_xy[0];
core_ptr->cam->cam_pos[1] += delta_xy[1];
if((key_is_pressed(core_ptr,core_ptr->kbd->move_front)) == 1 )
{
core_ptr->mov->y_vel -= core_ptr->mov->delta_accel;
}
if((key_is_pressed(core_ptr,core_ptr->kbd->move_back)) == 1 )
{
core_ptr->mov->y_vel += core_ptr->mov->delta_accel;
}
if((key_is_pressed(core_ptr,core_ptr->kbd->move_right)) == 1 )
{
core_ptr->mov->x_vel -= core_ptr->mov->delta_accel;
}
if((key_is_pressed(core_ptr,core_ptr->kbd->move_left)) == 1 )
{
core_ptr->mov->x_vel += core_ptr->mov->delta_accel;
}
core_ptr->mov->x_vel *= core_ptr->mov->delta_friction;
core_ptr->mov->y_vel *= core_ptr->mov->delta_friction;
printf("X VELOCITY = %lf\n",core_ptr->mov->x_vel );
printf("y VELOCITY = %lf\n",core_ptr->mov->y_vel );
So,basically this is working,the problem i'm facing btw is that when i press for example front+right,the speed is a lot higher cause it sums the 2 velocities,so i have double max speed and double accel...i really want to keep updating the positions togheter to let the friction always kickin in,but i didnt find any easy solution to this problem,ideally i would have only a single velocity,and i would update the 2 vectors accordinly but i have no idea i'm just lost...i hope someone is so gentle to help me with the math theory :/ bye