rel. distances... vector(my.x, my.y, my.z)

Posted By: SomebodyNew

rel. distances... vector(my.x, my.y, my.z) - 07/27/09 17:06

Hello everyone,
I wrote a script that lets the player fly an aircraft and shoot two missiles simultaneously from under its wings.
The script creates two "missile"-entities on the my.x, my.y etc coordinates +/- something (so that the missiles are created at the left and right ends of the aircrafts wings).

Now my first try looked like this (i left out all the unrelated code for a better overview):
Code:
function missiles()
{
	ent_create("missile.mdl", vector(plAIR.x + 50,plAIR.y + 50,0), rocket);
	ent_create("missile.mdl", vector(plAIR.x - 50,plAIR.y + 50,0), rocket);
	wait(1);
}


The problem was that the two missiles where always created using axis-coordinates +/- 50 quants (absolut coordinates). So my question is if there is a way to use relative coordinates where 0,0,0 is the entities position?
(the problem is not the angle of the missiles, thats already done - they're always shot in the direction the player is facing).

I've been able to go around that problem using some awfull long formulas (sin/cos plus each entity's individual collision model). I'm sure however that lite-c offers a better way to do this. I've looked in the manual but have not found anything there.

Thanks for your time.
Posted By: Storm_Mortis

Re: rel. distances... vector(my.x, my.y, my.z) - 07/27/09 20:20

you need to use a sinus calculation.
this shoulnt be this awfulf long ....

this may be wrong but, this should it look - just have a look at the manual to fix that:

function missiles()
{
ent_create("missile.mdl", vector(plAIR.x + 50 * sin(plAIR.pan),plAIR.y + 50 * sin(plAIR.pan,0), rocket);
ent_create("missile.mdl", vector(plAIR.x - 50 * sin(plAIR.pan,plAIR.y + 50 * sin(plAIR.pan,0), rocket);
wait(1);
}


if you spoke of this, im sorry but i dont know how to do this but using vertex coords(vec_for_vertex...)
Posted By: hopfel

Re: rel. distances... vector(my.x, my.y, my.z) - 07/27/09 20:54

There's a typo:

ent_create("missile.mdl", vector(plAIR.x - 50 * sin(plAIR.pan -->)<-- ,plAIR.y + 50 * sin(plAIR.pan,0), rocket);

wink
Posted By: SomebodyNew

Re: rel. distances... vector(my.x, my.y, my.z) - 07/27/09 21:00

Hey Storm_Mortis,
thanks for helping me out.
My initial function looked like this:
Code:
function missiles()
{
	ent_create("missile.mdl", vector(plSHIP.x+50*[color:#FF0000]+[/color]sin(plSHIP.pan), plAIR.y+50*cos(plAIR.pan), 0), rocket);
	ent_create("missile.mdl", vector(plAIR.x+50*[color:#FF0000]-[/color]sin(plAIR.pan), plAIR.y+50*-cos(plAIR.pan),0), rocket);
	wait(1);
}



I had those two mixed up... so these two missile launchers were rotating a bit wired. Only matching the Aircrafts rotation every 90°.
Then I made up some really long formulas... I feel so stupid now... a simple "-" and "+" mix up...

Thanks for showing me. That saved me quiet some time.

P.S.: The tutorial (chapter 8, at the end) states that a negative pan rotates the model counterclockwise and a positive pan rotates a model clockwise. It the other way around, isn't it?
If you create an entity and rotate it by positive 30 degrees it rotates counterclockwise (mathematical correct).
Well, just a detail.

Problem solved, thanks again.
© 2024 lite-C Forums