Camera.Target

Posted By: laethyn

Camera.Target - 01/24/07 04:20

As I posted elsewhere (in the wrong thread):

I've not updated in some time, so I don't know for certain if this has been implemented or not, but some sort of "target" function would be fantastic.

Something like

view 1stPerson
{
....
target = player;

}
or 1stPerson.target = player;

You get the idea.

This would be absolutely fantastic not only for views, but to point entities at other entities (ex. during combat, you set the player target to the monster, and the player constantly faces the target.

I realize this can be done via vec_to_angle et al. but having a .target handle the angles would be a lifesaver for a lot of people.
Posted By: PHeMoX

Re: Camera.Target - 01/24/07 05:48

I don't think it's more useful than the normal code we would use. I also wonder if it would be any faster, probably not since it will be checking the angles constantly.

Besides, you only need a few lines:

Code:

function turn_towards_target()
{
// get the direction from the entity MY to the entity YOU
vec_set(temp,your.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp); // now MY looks at YOU
}



Simplest approach would be to use pointers for your 'targets' like this:

Code:

entity* target1; //different kind of enemies
entity* target2;
[..]



Then you can use:

Code:

function turn_towards_target()
{
// get the direction from the entity player to the entity target1
vec_set(temp,player.x);
vec_sub(temp,target1.x);
vec_to_angle(target1.pan,temp);
// enemy now looks at player
}



Cheers
Posted By: Joey

Re: Camera.Target - 01/24/07 13:50

enhancing all that...
Code:
define spot_track, skill51;
define target, skill1;

function spot(ent)
{
if (ent == null) {
my.spot_track = 0;
my.target = null;
return;
}

my.target = handle(ent);
my.spot_track ++;

while (my.spot_track == 1) {
if (my.target != null) {
you = ptr_for_handle(my.target);
vec_set(temp.x, you.x);
vec_sub(temp.x, my.x);
vec_to_angle(my.pan, temp.x);
}
wait(1);
}
}



haven't tested that, though i think you get the idea of comfort you have with such little functions. so instead of requesting an "engine" feature, you should rather think over your problem once more.

joey.
Posted By: laethyn

Re: Camera.Target - 01/24/07 16:15

As said in my post, I'm aware it can be done, and I have no problems doing it, but let's count with me, shall we?

Here's some example code useing a "target" function:

Code:
1) action TheTarget
2) {
3) TargEnt = me;
4) }

5) action Player
6) {
7) player = me;
8) player.target = TargEnt;
9) }



That would be 9 lines of code.

Now let's lay out your code in the same manner:

Code:
1) define spot_track, skill51;
2) define target, skill1;
3) function spot(ent)
4) {
5) if (ent == null)
6) {
7) my.spot_track = 0;
8) my.target = null;
9) return;
10) }
11) my.target = handle(ent);
12) my.spot_track ++;
13) while (my.spot_track == 1)
14) {
15) if (my.target != null)
16) {
17) you = ptr_for_handle(my.target);
18) vec_set(temp.x, you.x);
19) vec_sub(temp.x, my.x);
20) vec_to_angle(my.pan, temp.x);
21) }
22) wait(1);
23) }
24)}



24 lines of code. Sure, there is a difference. But it's also about the EASE in which things are done for the end user. Making a panel in WED that then allows simple target selecting would be a fantastic boon for new users.
Posted By: Joey

Re: Camera.Target - 01/24/07 16:53

well, that is indeed correct.
Posted By: Doug

Re: Camera.Target - 01/25/07 00:36

Other than saving a few lines of code, there isn't any reason for this. It would either do too little to be very useful, or so much that it would slow things down.

Write a c-script function: function turn_to_ent(ENTITY* ent) and call it as needed. 8 lines of code for the function, 1 line of code to call it (3-4 if you want it to update it each frame).
Posted By: laethyn

Re: Camera.Target - 01/25/07 01:11

Like I said, I don't have a problem with it, just someone I was working with on something had been trying to figure out how to get something to "point" at another and this idea was brought up.

Cheers!
© 2024 lite-C Forums