Gamestudio Links
Zorro Links
Newest Posts
What are you working on?
by 3run. 02/28/20 09:28
Editting
by peterhw. 02/27/20 15:20
PS1 texturing bubbling ?
by 3run. 02/27/20 13:36
enum case / if else
by danatrader. 02/27/20 00:07
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
11 registered members (3run, Jerome8911, AndrewAMD, alibaba, txesmi, Sinuhet, Quad, FLD, Dalla, jenGs), 968 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Emrah06, zac, DebraSteed, Ricard, Apollo1
18379 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,169
Caucasus
3run Online
Senior Expert
3run  Online
Senior Expert

Joined: May 2009
Posts: 5,169
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
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,169
Caucasus
3run Online
Senior Expert
3run  Online
Senior Expert

Joined: May 2009
Posts: 5,169
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
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