0 registered members (),
1,397
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Moving an entity towards the center of the screen
#446939
11/07/14 03:45
11/07/14 03:45
|
Joined: Jun 2013
Posts: 108 Alberta, Canada
CanadianDavid
OP
Member
|
OP
Member
Joined: Jun 2013
Posts: 108
Alberta, Canada
|
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:
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:
#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?
|
|
|
Re: Moving an entity towards the center of the screen
[Re: 3run]
#446946
11/07/14 13:22
11/07/14 13:22
|
Joined: Jun 2014
Posts: 121
FEL
Member
|
Member
Joined: Jun 2014
Posts: 121
|
3run your website is a pretty helpfull one, i found Solutions for many of my problems in there. Could u maybe create a more complex sword/bow system? Just a little one. That would realy be something ultra awesome. So many people looking for something like this!
FEL - Lead Game Designer & Core Developer
|
|
|
Re: Moving an entity towards the center of the screen
[Re: FEL]
#446947
11/07/14 14:32
11/07/14 14:32
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
3run your website is a pretty helpfull one, i found Solutions for many of my problems in there. Could u maybe create a more complex sword/bow system? Just a little one. That would realy be something ultra awesome. So many people looking for something like this! Sorry for off-topic (thank you for kind words), but why don't you use 'Kingdom Hearts Movement'? greets
|
|
|
Re: Moving an entity towards the center of the screen
[Re: 3run]
#446950
11/07/14 18:18
11/07/14 18:18
|
Joined: Jun 2014
Posts: 121
FEL
Member
|
Member
Joined: Jun 2014
Posts: 121
|
Im reading that for the first time O.o what do i missed?
EDIT: I found old dead links about it... So would were we talking about?
Last edited by FEL; 11/07/14 18:23.
FEL - Lead Game Designer & Core Developer
|
|
|
|