still stuck with my phasers

Posted By: jigalypuff

still stuck with my phasers - 08/16/07 19:48

ok i am so very close to the effect i`m after for my game, but i have tried so many different things and all i have managed is to give myself a headache, although that may have been caused by banging my head off mm desk lol, i am going to post all the test code in the hopes that someone can tell me, how to scale a model on it`s x axis to an enemy model and not pass through it. i know this is a lot of code to ask you guys to look through, but believe me when i say i have tried my best but just can`t figure it out. thanks for any help.
Code:

var video_mode = 8;
var video_depth = 32;
var video_screen = 1;

sound beam_wav = <beam.wav>;

string stars_mdl = "stars.mdl";
string galor_mdl = "galor.mdl";
string excelsior_mdl = "excelsior.mdl";
string fphaser_mdl = "fphaser.mdl";

var distance_to;
var enemy_handle; // a global handle we can use for transferring pointers
var target_entity;
var scan_indicator;
var target_on;
var in_p;
var freeze_switch;
var camera_move_to[3];
var camera_distance = 200;
var camera_pan;
var camera_tilt;

entity* enemy;

define _target = 1;
define phaser skill12;
define ammo skill21;

string lockon = "lockon+3.tga";
string cphaser_mdl = "cphaser.mdl";

bmap hempire_tga = "hempire.tga";
bmap charge_pan_tga = "charge_pan.tga";
bmap charge_tga = "charge.tga";
bmap effect_tga = "effect.tga";

function stars();
function c_ship();
function f_ship();
function event_scn();
function got_target();
function c_phaser();
function got_shot();

panel Phaser_pan
{
bmap = charge_pan_tga;
pos_x = 945;
pos_y = 567;
window = 3, 2, 74, 7, charge_tga, player.phaser, 0; // can range from 0 to 74
flags = refresh, visible;
}

var phaser_decreasing = 0;
function init_player_startup()
{
while (player == null)
{
wait (1);
}
player.phaser = 74;
while (1)
{
if(phaser_decreasing == off)
{
player.phaser += 0.4 * time_step; // increase power slowly
player.phaser = min(74, player.phaser); // limit phaser power 74
}
wait (1);
}
}

function beam_weapons
{
while ((mouse_left == 1))
{
if(player.phaser <= 0) { break; }
phaser_decreasing = on;
player.phaser -= 3*time_step;
snd_play (beam_wav, 50, 0);
{
vec_for_vertex(temp,player,3894);
ent_create (fphaser_mdl, temp, c_phaser);
wait(1);
}
phaser_decreasing = off;
}
}

function c_phaser
{
///this needs to scale a model from the players vertex to the targeting sprite
///and run the got shot function
}

on_mouse_left = c_phaser;

function main
{
///init_radar();
mouse_map = hempire_tga;
mouse_mode = 1;
level_load ("new_beginings.wmb");
wait(1);
ent_create (stars_mdl, nullvector, stars);
ent_create (galor_mdl, vector(0, 0, 0), c_ship);
ent_create (excelsior_mdl, vector(300,0,0), f_ship);
// ent_create (excelsior_mdl, vector(200,40,0), f_ship);
//ent_create (excelsior_mdl, vector(-200, 40, 0), f_ship);
//ent_create (clouds_mdl, vector(1500, 10000, 0), clouds);
//ent_create (jungle_mdl, vector(25000, 10000, 0), planets);
//ent_create (clouds_mdl, vector(25000, 10000, 0), clouds);
while (1)
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
wait (5);
}
}

function target_detect()
{
enemy = my;
distance_to += 1;
if(event_type == event_detect && scan_indicator == _target && target_on == 0 && vec_dist(my.x,your.x) < distance_to)
{
target_on = 1;
enemy_handle = handle(you);
target_entity = handle(you);
ent_create(lockon, your.x, got_target);
}
}

function scan_targets()
{
while(1)
{
wait(-0.25);
if(target_entity != 0) { continue; }
scan_indicator = _target;
distance_to = c_scan(player.x, player.pan, vector(360, 60, 1000),ignore_me+ignore_you+scan_limit);
}
}

function c_ship()
{
in_p = 0;
freeze_switch = 0;
player = me;
my.ammo = 50;
my.scale_x = 1.0;
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
///my.transparent = on;
you = null;
my.enable_detect = on;
my.event = target_detect;
var ship_speed;
scan_targets();
while (1)
{
if (key_w == on)
{
if (ship_speed.x < 1)
{
ship_speed.x += 10.0 * time;
}
}
else
{
if (ship_speed.x >= 0)
{
ship_speed.x -= 0.05 * time;
}
}
if (ship_speed.x < 0) {ship_speed.x = 0;}
if (key_a == on)
{
my.pan += 3 * time;
}
if (key_d == on)
{
my.pan -= 3 * time;
}
if (ship_speed.z < 0) {ship_speed.z = 0;}
if (key_q == on)
{
my.tilt + = 3 * time;
}
if (ship_speed.z < 0) {ship_speed.z = 0;}
if (key_e == on)
{
my.tilt - = 3 * time;
}
ent_move (ship_speed.x, nullvector);
if
(key_p)
{
if (in_p == 0)
{
in_p = 1;
freeze_switch = 1 - freeze_switch;
}
}
else
{
in_p = 0;
}
if (freeze_switch == 0)
{
camera.pan -= mouse_force.x * 12 * time;
camera.tilt += mouse_force.y * 8 * time;
camera.tilt = clamp(camera.tilt,-30,10);
temp = fcos(camera.tilt,-camera_distance);
vec_set(camera.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera.tilt,-camera_distance)));

vec_diff(temp.x,camera.x,my.x); //find the vector from the player to the camera
vec_normalize(temp.x,16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(temp.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.

trace_mode = ignore_me+ignore_passable+ignore_models;
result = trace(my.x,temp.x); //trace from the player to 16 quants behind the camera.
IF (result > 0) {
vec_diff(temp.x,my.x,target.x); //find the vector from the point the trace hit to the player
vec_normalize(temp.x,16); //get the magnitude of this vector to 16 quants and store in temp
vec_set(camera.x,target.x); //place the camera at the trace hit point
vec_add(camera.x,temp.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
}

}
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()
{
wait(1);
}

function got_target
{
my.scale_x = 0.1;
my.scale_y = my.scale_x;
my.oriented = on;
my.facing = off;
you = ptr_for_handle(enemy_handle); // now YOU is the enemy

while(you != null)
{
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);
}
target_entity = 0;
target_on = 0;
ent_remove(me);
}

function got_shot()
{
if (event_type == event_block
|| event_type == event_entity
|| event_type == event_impact) {
my._hull -= 10;
}
}


Posted By: LogantheHogan

Re: still stuck with my phasers - 08/16/07 20:26

Hey man, sorry I didn't reply to your PM sooner, and the reply I did send was kind of lame. I've been learning how to program in C# the past couple days and it's taking all my focus (and energy) so I didn't really have a good answer for you.

Here are my two thoughts on this.

1. I have never tried to do what you are doing with weapons, i.e. scale a model to a certain size instead of move it to a certain point. The reply I sent you mentioned vec_dist(), which I know you'll need to use, but I honestly have no idea how to scale a model on its X axis so that it spans a certain number of quants. All I know is my.scale_x = ?. I'm not even sure if this is entirely possible, which leads to my next thought.

2. I don't think using a model is the best way to be doing this. You can write a particle function that does the same thing as what you're trying to do with a model, and frankly using particles would probably be a lot faster and look a lot cooler as well.

So, there ya go. That's another reason why I wasn't being too reply-happy; you stumped me.

But seriously. I'd download EasyParticle 3 or look at the template particle scripts and get an idea of how to write a particle function to do what you're trying to do. Unless you NEED a model, in which case, well... yeah.

So there ya go. God bless.
Posted By: jigalypuff

Re: still stuck with my phasers - 08/16/07 20:39

the reason i was useing a model is because i saw it used in the star wars demo posted a while back in showcase 1 and it seemed to be just what i was after, i have tried doing this with particles but i failed miserably at that as well. i`ll try doing a partical function and hope for the best, if anyone can help solve this you`ll have my eternal gratitude, either useing particals or a model.
good luck with your studies logan, and thank you.
Posted By: LogantheHogan

Re: still stuck with my phasers - 08/16/07 20:56

Then I stand corrected; it is possible. Regardless, I still have no clue how to do it. When you find out, let me know. Haha.

And don't hesitate to ask me any more questions. C# is easy enough to learn, I think I've definitely got the hang of it. So that won't be distracting be anymore.
Posted By: jigalypuff

Re: still stuck with my phasers - 08/17/07 07:37

if i ever find out i`ll post it in user contributions so noone ever has to go through this again lol, i`ll keep pluging away at it and hope someone out there knows how to achieve this and come save my sanity lol
Posted By: Bot190

Re: still stuck with my phasers - 08/17/07 10:13

The only thing i can think of is to have a block that is as big as the gun ever gets and have it follow around at the same position the gun is, invisible...
Posted By: jigalypuff

Re: still stuck with my phasers - 08/17/07 10:55

well it`s not a gun lol, it`s a spaceship. i`m not to sure what you mean though, i thought if i declared an entity like entity* enemy then i could use that as a pointer for the mesh to go to like my_scale.x = enemy.x; but that fails, eve nwhen it hits the enemy it passes through. and if the enemy is movewing as i will be then it wont be possible to use a block would it? i`d get the same problem of the beam passing through the enemy and seeing it passing out the other side.
Posted By: Bot190

Re: still stuck with my phasers - 08/17/07 11:28

well, in the manual it says that the collision hull doesn't change im guessing thats your problem, the engine doesn't know that it hit the other model becuase collision detection doesn't work, so i thought if you have a box thats as big as the beam(im guessing thats what your scaling?)and use that for collision detection. oh and wouldn't that just make it scale so the beams x is the same as the enemys x? tonight I'll look at the code and see if i can come up with something.
Posted By: jigalypuff

Re: still stuck with my phasers - 08/17/07 12:27

well i hope to god you can, i am so stuck i`m like the king of stuck in stucktown on stuckday lol, everything i have tried has failed and now i can`t even get the damn thing to scale anymore lol, i dunno were i went wrong lol
Posted By: Bot190

Re: still stuck with my phasers - 08/17/07 21:09

could you post what you have tried? if you have it still.
Posted By: jigalypuff

Re: still stuck with my phasers - 08/17/07 21:13

well here is what i currently have, the bea mworks but will not follow the enemy or the target sprite, and it passes through the enemy but still causes damage, the problem with this is any enemy near enough to the shot one will also get hit, and shields will be useless. all the code is the same as i have posted bar this. this is all the beam weapon code


var phaser_decreasing = 0;
function init_player_startup()
{
while (player == null)
{
wait (1);
}
player.phaser = 74;
while (1)
{
if(phaser_decreasing == off)
{
player.phaser += 0.4 * time_step; // increase power slowly
player.phaser = min(74, player.phaser); // limit phaser power 74
}
wait (1);
}
}

function beam_weapons
{
while ((mouse_left == 1))
{
if(player.phaser <= 0) { break; }
phaser_decreasing = on;
player.phaser -= 3*time_step;
snd_play (beam_wav, 50, 0);
vec_for_vertex(temp,player,3894);
ent_create (fphaser_mdl, temp, c_phaser);
wait(1);
}
phaser_decreasing = off;
}

var phaser_speed;

function c_phaser
{
wait(1);
c_setminmax(me);
my.scale_x = enemy;
my.scale_y = 0.2;
my.scale_z = 0.2;
my.passable = off;
my.oriented = on;
my.flare = on;
my.bright = on;
my.ambient = 100;
my.pan = player.pan;//--->player.pan and tilt set to camera
my.tilt = player.tilt;
my.enable_entity = on;
my.enable_block = on;
my.enable_impact = on;
my.polygon = on;
phaser_speed.x = 50 * time;
phaser_speed.y = 0;
phaser_speed.z = 0;
while (my != null)
{if
(my.roll > 150){my.passable = off;}
my.roll += 25 * time;
c_move(my,vector(phaser_speed*time,0,0),nullvector,ignore_you);///
my._frameCt += 1;
if (my._frameCt >= 20) { break; }
wait(1);
}
if (me != null)
{ ent_remove(me);
}
}


Posted By: Bot190

Re: still stuck with my phasers - 08/17/07 21:27

first off, do you have aim? second, the beam just goes right through the enemy forever right? also, how far are the enemys from the beam when they take damage... it would also help if i could either get the files for the game so i could see it and work on it, or if you posted a video so i could get an idea of whats wrong...
Posted By: jigalypuff

Re: still stuck with my phasers - 08/17/07 21:42

there is a targeting sprite and function yes, i can`t figure on how to get it to tie in to the beam weapon though, i have some examples i have been trying. i have zipped up the test level and here is the link, good luck and thanks for helping me out.
http://www.4shared.com/file/22274751/fbf5ac3b/test_level.html
sorry, i forgot to say, it does not have to be a model, if it ca nbe achieved with particles that is just as good. thnks again
Posted By: vlau

Re: still stuck with my phasers - 08/20/07 15:41

I found this topic very interesting, so I spent a few hours
on that.

You may try my phaserTarget demo, download it under my sig.
One important thing is the phaser model, you need to position
it well in MED in order to let it scale probably in game,
I think you've already know it.

If you want to use your own phaser, you may follow my setting
in MED :

MED->File->Preference->Video Out :

Check 2d Grid, Grid Lo = 1.00, Grid Hi = 4.

Load the phaser.mdl, on Topview, zoom in very very close
and see how I position and scale the vertices at the
worldposition centre and its size.

Hope this helps.
Posted By: jigalypuff

Re: still stuck with my phasers - 08/20/07 15:44

woo freaky i was just writeing to ask if anyone had gotten anywere when gmail let it be known you had replied to the thread lol, you must have read my mind. i am dl`ing you demo now, thanks and i`ll let you know how it goes
Posted By: vlau

Re: still stuck with my phasers - 08/20/07 15:49

Ah, I've forgot to mention the following instruction in my level :

"LMB = Fire phaser"

Good luck!
Posted By: jigalypuff

Re: still stuck with my phasers - 08/20/07 17:34

it does seem to work the way i need, it stops when it hits an enemy, getting it to work with my existing code is proveing problamatic lol, but i shall persevere.
Posted By: jigalypuff

Re: still stuck with my phasers - 08/20/07 21:00

well i`m stumped again, i just can`t seem to integrate this stoping thingy into my code, nor to follow the targeting sprite, anyone got any ideas at all on how i can work this? please.
Posted By: ShoreVietam

Re: still stuck with my phasers - 08/21/07 21:14

Without reading any of that stuff I can tell you in a few words, how it works.

1. Create your beam model with the length of 1 quant in MED (don't center it, it has to start at the cetner and has to go 1 quant into x direction).
2. use c_trace with my.polygon = on (or whatever this is called now) like this:
RESULT = c_trace(vec_from.x, vec_to.x, ignore_something)
vec_set(my.x, vec_from.x);
vec_diff(temp.x,vec_to.x, vec_from.x);
vec_to_angle(my.pan, temp.x);
my.scale_x=RESULT;


something like that, or take a look nito my Star Wars code:
function FNCT_LaserBeam(fptr, tptr, AppVTX)



Posted By: badapple

Re: still stuck with my phasers - 08/22/07 04:48

i have just posted a laser contribution in user contributions if that helps
© 2024 lite-C Forums