Posted By: CanadianDavid
Moving an entity towards the center of the screen - 11/07/14 03:45
I have a simple code that shoots a rocket out of a weapon with the expected position being the center of the screen. I use vec_to_angle to alter the pan and tilt of the rocket when it leaves the weapon barrel (vec_for_vertex) and move it forward along the x direction using a c_move instruction:
However, with the above technique, the rockets do not hit the direct center of the screen but arrive slightly off-center:
It appears the offset is affected by the model alignment despite using vec_to_angle:
Is there something wrong with my approach? How can I properly get the rockets to hit the center of the screen?
Code:
VECTOR temp; vec_set(temp, vec_for_screen(vector(screen_size.x/2, screen_size.y/2, 10000), camera)); vec_to_angle(rocket.pan, vec_diff(NULL,temp.x,rocket.x)); while(1){ c_move(rocket, vector(4*time_step, 0, 0), nullvector, IGNORE_FLAG2); wait(1); }
However, with the above technique, the rockets do not hit the direct center of the screen but arrive slightly off-center:
It appears the offset is affected by the model alignment despite using vec_to_angle:
Code:
#include <acknex.h> #include <default.c> BMAP* center_bmp = "center.bmp"; PANEL* center_pan = { bmap = center_bmp; flags = SHOW; } void shoot_rocket(ENTITY* rocket) { set(rocket, FLAG2); vec_for_vertex(rocket.x, player, 987); VECTOR temp; vec_set(temp, vec_for_screen(vector(screen_size.x/2, screen_size.y/2, 10000), camera)); vec_to_angle(rocket.pan, vec_diff(NULL,temp.x,rocket.x)); while(1){ c_move(rocket, vector(4*time_step, 0, 0), nullvector, IGNORE_FLAG2); wait(1); } } void player_action() { player = me; while(1) { camera.pan -= mouse_force.x; camera.tilt += mouse_force.y; vec_set(camera.x, player.x); camera.pan = player.pan; camera.tilt = player.tilt; if(mouse_left) { ENTITY* rocket = ent_create("rocket.mdl", nullvector, NULL); shoot_rocket(rocket); } wait(1); } } void main(){ level_load("level1.wmb"); wait(1); center_pan.pos_x = (screen_size.x-bmap_width(center_bmp))/2; center_pan.pos_y = (screen_size.y-bmap_height(center_bmp))/2; ent_createlocal("rocketgunhands.mdl", nullvector, player_action); }
Is there something wrong with my approach? How can I properly get the rockets to hit the center of the screen?