|
a query about c_scan
#147308
08/11/07 16:46
08/11/07 16:46
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
i am trying to write a targeting code, i figured c_scan would be the best thing for this as c_trace only goes in a straight line and this is for a spaceship, which should be able to scan all around itself. i want it to run all the time, but i`m a bit stumped on how this actually works, all the tuts seem to require a button being pressed, but i want it to scan automaticly then if it finds a target i want it to lock on to that target untill it is destroyed. i have a bit of test code and would dearly love some pointers on which way to work this, thanks. Code:
function c_ship { player = my; my.scale_x = 1.0; my.scale_y = my.scale_x; my.scale_z = my.scale_x; while(1) { if (key_1 == on) { c_scan(player.x, temp, vector(360, 60, 1000), ignore_me); } wait(1); } }
function f_ship { enemy = my; my.scale_x = 2.0; my.scale_y = my.scale_x; my.scale_z = my.scale_x; my.enable_scan = on; my.event = event_scn; }
function event_scn() { if (event_type == event_scan) { ent_create(lockon, my.x, got_target); } }
function got_target { my.scale_x = 0.1; my.scale_y = my.scale_x;////scale the sprite so it`s no huge }
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
Re: a query about c_scan
[Re: LogantheHogan]
#147310
08/11/07 17:14
08/11/07 17:14
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
excellent job mate thanks, now to try and get it to work as a target lol. damn i spoke to soon, i added another enemy into the test and the targeting sprite also appears on that one, i need to be able to terget only one enemy at a time, is there a way to stop the scan after it has gotten the closest target and the nrestart after that enemy is dead?
Last edited by jigalypuff; 08/11/07 17:22.
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
Re: a query about c_scan
[Re: jigalypuff]
#147311
08/11/07 17:20
08/11/07 17:20
|
Joined: Sep 2002
Posts: 700 Orange County, CA
LogantheHogan
Developer
|
Developer
Joined: Sep 2002
Posts: 700
Orange County, CA
|
Well, for that I'd just write a script that makes the target entity always at the same location as the enemy (but a litte bit forward so it isn't clipped) and then just write a code that says if(something is targeted) { fire the weapon in the direction of the target and not the regular direction } If you want your weapons to lock onto the target and "seek" it, that's deceptively easy as well. Just call vec_to_angle every frame during the movement function of the weapon. If you want any examples or anything please let me know.
|
|
|
Re: a query about c_scan
[Re: LogantheHogan]
#147312
08/11/07 17:23
08/11/07 17:23
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
examples would be great, it is far easier for me to look at code and figure it out than write my own from scratch, i`m a total novice at this lol
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
Re: a query about c_scan
[Re: LogantheHogan]
#147313
08/11/07 17:29
08/11/07 17:29
|
Joined: Sep 2002
Posts: 700 Orange County, CA
LogantheHogan
Developer
|
Developer
Joined: Sep 2002
Posts: 700
Orange County, CA
|
For the target to follow the enemy around, I'd try this: Code:
var enemy_handle; // a global handle we can use for transferring pointers
function event_scn() { if (event_type == event_scan) { enemy_handle = handle(you); ent_create(lockon, my.x, got_target); } }
function got_target { my.scale_x = 0.1; my.scale_y = my.scale_x;////scale the sprite so it`s no huge you = ptr_for_handle(enemy_handle); // now YOU is the enemy while(you) { vec_set(temp,player.x); vec_sub(temp,my.x); vec_to_angle(my.pan,temp); // turn the target toward the player
vec_set(temp,nullvector); temp.x = 20; // change this if you need to - the distance in front of the enemy vec_rotate(temp,my.pan); vec_add(temp,your.x); vec_set(my.x,temp);
wait(1); } }
The temp.x = 20 line might need to be temp.x = -20, but I'm not sure, I haven't done the math. Test that and see how it serves you.
|
|
|
Re: a query about c_scan
[Re: LogantheHogan]
#147314
08/11/07 17:36
08/11/07 17:36
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
well that seems to work ok apart from the targeting sprite appears over both enemys, i need to target one at a time i added another enemy into the test and the targeting sprite also appears on that one, i need to be able to terget only one enemy at a time, is there a way to stop the scan after it has gotten the closest target and the nrestart after that enemy is dead? with the temp.x = i had to put 120, anything over that and they don`t appear, i`m guessing that 120 is how far away the enemy is from my ship
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
Re: a query about c_scan
[Re: jigalypuff]
#147315
08/11/07 17:44
08/11/07 17:44
|
Joined: Sep 2002
Posts: 700 Orange County, CA
LogantheHogan
Developer
|
Developer
Joined: Sep 2002
Posts: 700
Orange County, CA
|
Okay, cool. So in the player action, inside the while(1) loop, put the c_scan and stuff inside an "if(!you)" statement. And, the temp.x value is actually the distance from the TARGET SPRITE to the enemy ship, not the player ship from the enemy ship. I just included that value so you could set the target a little in front of the enemy ship so that it doesn't look all bad. And P.S. - don't overestimate the size of quants. 120 quants is a pretty short distance. In fact, it's as far as the target sprite is away from the enemy ship.
|
|
|
Re: a query about c_scan
[Re: LogantheHogan]
#147316
08/11/07 18:25
08/11/07 18:25
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
do you mean like this? cos the sprite no longer appears for some reason Code:
function c_ship { player = my; my.scale_x = 1.0; my.scale_y = my.scale_x; my.scale_z = my.scale_x; while(1) { if(!you) { c_scan(player.x, temp, vector(360, 60, 1000), ignore_me); wait(-0.25); } wait(1); } }
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
|