Posted By: Denn15
vec_rotate problem - 12/07/12 08:49
i have a ball in my level that you can control using the asdw keys and i would like to make the controls relative to the camera so that when you for example press w it wil move forward in the direction of the camera.
ive tried to use vec_rotate for this but the ball acts all weird when i do that. when i roll backwards the ball floats up in the air and when i roll forward the ball slams into the ground and other times the ball just moves really slow.
im guessing that the vector is pointing in a wrong direction but i cant figure out how to fix it.
ive tried to use vec_rotate for this but the ball acts all weird when i do that. when i roll backwards the ball floats up in the air and when i roll forward the ball slams into the ground and other times the ball just moves really slow.
im guessing that the vector is pointing in a wrong direction but i cant figure out how to fix it.
Code:
var campan; var camtilt = - 5; var camx; var camy; while (1) { ball_force.x = (key_d-key_a)*30*time_step; ball_force.y = (key_w-key_s)*30*time_step; ball_force.z = 0; vec_rotate (ball_force, camera.pan); pXent_addtorqueglobal (ball, vector(ball_force.x, 0, 0)); //spin the ball x axis pXent_addtorqueglobal (ball, vector(0, ball_force.y, 0)); // spin the ball y axis camera.x = ball.x - 500 * cos(-camx) * cos(camy); camera.y = ball.y - 500 * sin(-camx) * cos(-camy); camera.z = ball.z - 500 * sin(camy); camera.pan = - campan; camera.tilt = - camtilt; ball_move.x = (key_w-key_s)* 1400 * time_step; ball_move.y = (key_a-key_d)* 1400 * time_step; vec_rotate (ball_move, camera.pan); pXent_addforcecentral( ball, ball_move); camx = camx + mouse_force.x; camy = camy + mouse_force.y; campan = campan + mouse_force.x; camtilt = camtilt - mouse_force.y; wait (1); }