Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (degenerate_762), 1,098 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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
C
CanadianDavid Offline OP
Member
CanadianDavid  Offline OP
Member
C

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:

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?

Re: Moving an entity towards the center of the screen [Re: CanadianDavid] #446940
11/07/14 07:01
11/07/14 07:01
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Take a look at this example, I've made it a long time ago, but it may give you an idea (I'll think of better idea). I see creating rocket at camera.x and rotate it with camera.pan isn't an option in your situation.

badcom.at.ua/load/3dgs_stuff/aiming_in_3rd_person/3-1-0-19


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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
F
FEL Offline
Member
FEL  Offline
Member
F

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 Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: FEL
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


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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
F
FEL Offline
Member
FEL  Offline
Member
F

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

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1