Keep sprite faced at the camera.

Posted By: Realspawn

Keep sprite faced at the camera. - 07/10/16 17:20

I use this sprite for bullet and it moves as it should to the player
how ever it turns. How can i make the sprite move this way but keep facing the camera. Working on a new tutorial and its the last piece of the puzzle needed laugh


thank you for your time\

Code:
action e_bullet()
{
	set(my,BRIGHT);
	my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT); 
	my.event = ice_hit;
	c_setminmax(me);

	VECTOR temp;
	while(!surfer1){wait(1);
	}
	while(1)
	{


		c_move(my, vector(-5* time_step, 0, 0), nullvector, NULL | IGNORE_SPRITES | IGNORE_PASSABLE);
		vec_set(temp, surfer1.x);
		vec_sub(temp, my.x); 
		
		vec_to_angle(my.pan , temp); 
		wait(1);

		
		
	}
}

Posted By: Ch40zzC0d3r

Re: Keep sprite faced at the camera. - 07/10/16 17:31

Facing the camera:
Code:
VECTOR tmp;
vec_set(tmp, camera.x); 
vec_sub(tmp, my.x);
vec_to_angle(my.pan, tmp);



Save the angle you need somewhere else like in a skill or the like:
Code:
Set angle to the c_move direction
c_move()
face player

Posted By: Realspawn

Re: Keep sprite faced at the camera. - 07/10/16 17:55

thx not sure how to make it work. With what i have the bullet sprites go the right way and follow the player till hit. But it looks like the pan is facing always in the direction of the player even with you script added.
Posted By: Anonymous

Re: Keep sprite faced at the camera. - 07/10/16 18:12

Set it's pan always to 0

Then using abs movement not rel movement to chase the player.

I'll post a bit of code later if no one else does.

Manual
Quote:
Angles have a special meaning with sprites. If all angles are at zero, the sprite will stand upright and horizontally face the camera. If its pan or tilt angle is nonzero, the sprite is oriented in world space according to its angles. If pan and tilt both are 0, but the roll angle is nonzero, the sprite is always perpendicular to the camera. This is useful for spherical objects, like fireballs or explosions. For an angle to be nonzero it's sufficient to set it at a small amount, like 0.01.

http://www.conitec.net/beta/aentity-pan.htm
Posted By: Ch40zzC0d3r

Re: Keep sprite faced at the camera. - 07/10/16 18:14

If you know exactly where it has to go you can use absolute movement in c_move, or you do what I said and set the angles before calling c_move and then change them back to face the camera.
Posted By: Anonymous

Re: Keep sprite faced at the camera. - 07/10/16 18:27

-- Ch40zzC0d3r's solution is perfectly valid and working..
Posted By: Realspawn

Re: Keep sprite faced at the camera. - 07/10/16 18:34

have to go to work dive into this stuff tomorrow i am very close laugh
Posted By: NeutronBlue

Re: Keep sprite faced at the camera. - 07/11/16 22:08

Not sure if this works for moving sprites (as an 'entity') - but what about the "Oriented" flag for sprites??
Posted By: Anonymous

Re: Keep sprite faced at the camera. - 07/11/16 23:09

ORIENTED, FACING replaced as of A6

http://www.conitec.net/beta/aAnhang_Syntax.htm
Posted By: Anonymous

Re: Keep sprite faced at the camera. - 07/11/16 23:19

if vSpeed is your rate. Rel movement can be converted to abs movement as fallows.
Code:
var vSpeed = 5; 
VECTOR vec_move; 
while()...
vec_set(vec_move,vector(key_w-key_s,key_a-key_d,0));
vec_rotate(vec_move,my.pan);
c_move(my,nullvector,vec_scale(vec_move,vSpeed*time_step),FLAGS);

...
// using abs movement your pan/tilt/roll can stay 0//


--Edit Thou vec_normalize maybe a better choice. http://www.conitec.net/beta/avec_normalize.htm
However -Ch40zzC0d3r solution is perfectly valid also.

Take Care --
Posted By: Realspawn

Re: Keep sprite faced at the camera. - 07/12/16 15:23

The solution of Ch40zzC0d3r works like as charm laugh

so for others that encounter this programm here is the script that i use now and works.


Code:
action e_bullet()
{
	set(my,PASSABLE | BRIGHT );
	my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT); 
	my.event = ice_hit;
wait(1);
	c_setminmax(me);
	my.lightrange = 100;
	my.ambient =255;

	VECTOR temp;//declare temp vector
	while(!surfer1){wait(1);
	}
	while(1)
	{
		if(vec_dist(my.x,enemy.x) >120){
			reset(my,PASSABLE);
		}
		//Set angle towards player
		vec_set(temp, surfer1.x);
		vec_sub(temp, my.x); 
		vec_to_angle(my.pan , temp);

		//Will use relative movement facing the player
		c_move(my, vector(5* time_step, 0, 0), nullvector, IGNORE_SPRITES | IGNORE_PASSABLE);

		//Change angle now so it faces camera
		vec_set(temp, camera.x); 
		vec_sub(temp, my.x);
		vec_to_angle(my.pan, temp);

		wait(1); //The angle will stay this way until the next frame loads (aka visible part of the frame)




		
	

		
		
	}
}

Posted By: rayp

Re: Keep sprite faced at the camera. - 07/12/16 19:33

Remove the NULL from c_move it makes no sense for me btw.

edit: And you forgot to wait one frame with the c_setminmax instruction.
edit2: Not sure but isnt there one wait(1) too much? If not i would recomment to use wait(2) instead grin
Absolute movement would be better here, but iam too stupid to calculate the vectors grin
Posted By: Realspawn

Re: Keep sprite faced at the camera. - 07/12/16 21:06

if your to stupid hahah what does it make me grin

changed it in the post laugh
Posted By: Ch40zzC0d3r

Re: Keep sprite faced at the camera. - 07/12/16 22:04

Originally Posted By: rayp
Remove the NULL from c_move it makes no sense for me btw.

edit: And you forgot to wait one frame with the c_setminmax instruction.
edit2: Not sure but isnt there one wait(1) too much? If not i would recomment to use wait(2) instead grin
Absolute movement would be better here, but iam too stupid to calculate the vectors grin


The absolute movement is what I said earlier, but I knew you want an easy solution so I didnt post that code.
In the end its just as simple as this:
Code:
VECTOR vAbs;
vAbs.x = speed * sinv(DegToRad(angDir.pan));
vAbs.y = speed * cosv(DegToRad(angDir.pan));
vAbs.z = speed * sinv(-DegToRad(angDir.tilt));



Not sure with the signs though
Posted By: Kartoffel

Re: Keep sprite faced at the camera. - 07/13/16 11:25

I don't see why relative movement should be bad but you can also take a relative movement vector and use vec_rotate(&vMove, &ent->pan);
Then you can use it as an absolute vector.

I'm pretty sure that's what the function does with relative movement vectors anyway.
Posted By: Anonymous

Re: Keep sprite faced at the camera. - 07/13/16 15:05

By changing the pan to use rel movement to face the target you void the engines automatic 'always face the camera' behavior, is all.

By the way - this is the same answer I've already posted.

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=460722#Post460722
© 2024 lite-C Forums