Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (kzhao, AndrewAMD, bigsmack), 824 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
a query about c_scan #147308
08/11/07 16:46
08/11/07 16:46
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline OP
Serious User
jigalypuff  Offline 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: jigalypuff] #147309
08/11/07 17:10
08/11/07 17:10
Joined: Sep 2002
Posts: 700
Orange County, CA
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

Joined: Sep 2002
Posts: 700
Orange County, CA
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)
{
c_scan(player.x, temp, vector(360, 60, 1000), ignore_me);
wait(-0.25); // we musn't scan every frame; c_scan is too slow for that
}

}



I just took out the IF statement and put in a larger wait value. It scans permanently every quarter second. See if that's more like what you're looking for?

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 Offline OP
Serious User
jigalypuff  Offline 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
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

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 Offline OP
Serious User
jigalypuff  Offline 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
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

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 Offline OP
Serious User
jigalypuff  Offline 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
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

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 Offline OP
Serious User
jigalypuff  Offline 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!
Re: a query about c_scan [Re: jigalypuff] #147317
08/11/07 18:28
08/11/07 18:28
Joined: Sep 2002
Posts: 700
Orange County, CA
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

Joined: Sep 2002
Posts: 700
Orange County, CA
Hmm. Yeah that's what I meant. Try a you = null right before the while(1).

Page 1 of 3 1 2 3

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