Author |
Topic: How do I make my angle-specific script.... generic? |
9837265498 |
|
General Member Since: Nov 6, 2009 Posts: 193 Last: Jan 23, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Sunday, Jan. 23, 2011 03:47 pm |
|
I am currently working on a drawbridge script that i want to be "generic" so as to work for any instance of my prefab, no matter if it is rotated yaw in the worldspace.
I have a script origin in the prefab and my simple understanding of scripting tells me it is possible to make the origin's angles the angles of the "Bridge" and then rotate accordingly to what that value is.
I would be easily content if it worked for even just the 4 major directions (0, 90, 180, 270 degrees).
this is what i have so far:
Code: main()
{
trigger = getentarray("drawbridge","targetname");
for(i=0;i<trigger.size;i++)
trigger[i] thread bridge_think();
}
bridge_think()
{
self.bridgemoving = false;
self.bridgeclosed = true;
self.bridge = getent(self.target,"targetname");
self.bridgenode = getent(self.bridge.target,"targetname");
self.bridge.angle = self.bridgenode.angles;
while (1)
{
self waittill("trigger");
if(!self.bridgemoving)
self thread bridge_move();
}
}
bridge_move()
{
self.bridgemoving = true;
if(self.bridgeclosed)
{
self.bridge rotateroll(-90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = false;
}
else
{
self.bridge rotateroll(90,4);
self.bridge waittill("rotatedone");
self.bridgeclosed = true;
}
self.bridgemoving = false;
}
This version of bridge_move() is cut down to one direction and i would like to know how i should go about setting it up for all 4. Also is my "self.bridge.angle = self.bridgenode.angles;" usable to make it more efficient?
any and all input is appreciated, ty
|
|
|
|
cskiller86 |
|
General Member Since: Nov 23, 2009 Posts: 528 Last: Oct 25, 2011 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Sunday, Jan. 23, 2011 04:48 pm |
|
You can use this:
Code: anglesToRight(bridge.angles) //this returns the right angles of "bridge" as a vector; if you need the other angles, use anglesToForward() or anglesToUp
bridge_angle = maps\mp\_utility::vector_scale(anglesToRight(bridge.angles), 90) //this gets the right angles of "bridge" and then multiplies it with 90; so it turns your object 90 degrees, no matter how it's rotated in Radiant
_INSANE_ taught me this, so thank him... if it works :P |
|
|
|
9837265498 |
|
General Member Since: Nov 6, 2009 Posts: 193 Last: Jan 23, 2012 [view latest posts] |
|
|
|
9837265498 |
|
General Member Since: Nov 6, 2009 Posts: 193 Last: Jan 23, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Sunday, Jan. 23, 2011 06:22 pm |
|
I could easily be going about this wrong but my two bridge are no longer responding at all, and the one that is flipped 180 degrees has rotated his bridge to match 0 degrees.... confusion is rampant.
Here is what i tried:
Code: bridge_think()
{
self.bridgemoving = false;
self.bridgeclosed = true;
self.bridge = getent(self.target,"targetname");
self.bridgenode = getent(self.bridge.target,"targetname");
self.bridge.angles = self.bridgenode.angles;
while (1)
{
self waittill("trigger");
if(!self.bridgemoving)
self thread bridge_move();
}
}
bridge_move()
{
self.bridgemoving = true;
if(self.bridgeclosed)
{
// self.bridge rotateroll(-90,2);
// self.bridge waittill("rotatedone");
self.bridge_angles = maps\mp\_utility::vector_scale(anglesToUp(self.bridge.angles), -90);
self.bridgeclosed = false;
}
else
{
// self.bridge rotateroll(90,4);
// self.bridge waittill("rotatedone");
self.bridge_angles = maps\mp\_utility::vector_scale(anglesToUp(self.bridge.angles), 90);
self.bridgeclosed = true;
}
self.bridgemoving = false;
}
what should I change? |
|
|
|
cskiller86 |
|
General Member Since: Nov 23, 2009 Posts: 528 Last: Oct 25, 2011 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Monday, Jan. 24, 2011 09:03 am |
|
Oh, wait, you misunderstood me... or maybe I misunderstood. But it would help if I had a picture.
Anyway, the vector_scale command works instantaneous. You still need to do a rotateyaw (or rotateroll) and set the time of rotation.
Here's an example of what I used:
Code: PlayFX(fordfxfire, fordd.origin + maps\mp\_utility::vector_scale(anglesToRight(fordd.angles), 20) + maps\mp\_utility::vector_scale(anglesToUp(fordd.angles), 10));
I needed to play an FX on a specific point of an xmodel, no matter how that xmodel was rotated in Radiant; so the FX played on a point that was 20 units to the side and 10 units high of the xmodel's origin.
Another way to do it is to have cases, but it won't be 100% general.
pseudocode:
if bridge angle on X axis is 0, do a rotateyaw of 90
else
if bridge angle on X axis is 180, do a rotateyaw of -90
else
if bridge angle on X axis is 90, do a rotateroll of 90
else
if bridge angle on X axis is 270, do a rotateroll of -90
else do nothing
However, your bridge would have to be positioned straight on the horizontal axis. |
|
|
|
.KiLL3R. |
|
General Member Since: Oct 26, 2006 Posts: 1437 Last: Jul 3, 2017 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Monday, Jan. 24, 2011 01:00 pm |
|
I'm guessing the bridge is a script_brushmodel, if it is then it's angle always starts at 0 0 0 no matter which why you place it.
To get around it you must manually enter the angle it's meant to be at in its angles property (meaning you'll need a new prefab for each angle you use it at).
So for a bridge at 90 degrees
Code:
Key: angles
Value: 0 90 0
This will have no effect in radiant, but once compiled it will be rotated 90 degrees and your first rotateroll script should work perfectly with it. |
|
|
|
9837265498 |
|
General Member Since: Nov 6, 2009 Posts: 193 Last: Jan 23, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Tuesday, Jan. 25, 2011 01:52 am |
|
I am probably not very clear when it come to explaining so maybe this picture will help (attachment).
yes, my bridge is a script_brushmodel within a prefab, and i have multiple instances of my prefab in my test map. I have one facing 0 and another facing 180.
I would like to, at the very least, get my script able to work in the four major directions (0, 90, 180, 270), if not all possible yaw.
cskiller86 Quote: Another way to do it is to have cases, but it won't be 100% general.
pseudocode:
if bridge angle on X axis is 0, do a rotateyaw of 90
else
if bridge angle on X axis is 180, do a rotateyaw of -90
else
if bridge angle on X axis is 90, do a rotateroll of 90
else
if bridge angle on X axis is 270, do a rotateroll of -90
else do nothing
i believe this should make the 4 major directions work, but i tried this on my own before and it didnt respond. I may have had the "else if" syntax wrong because I just guessed it would be just:
Code: else if(condition);
{
do stuff
}
is that correct?
.KiLL3R Quote: To get around it you must manually enter the angle it's meant to be at in its angles property (meaning you'll need a new prefab for each angle you use it at).
by this do you mean I set that value in the the prefab's angles?
Or do i make 4 different prefabs with different angle setting within the script_brushmodel (bridge0, bridge90, bridge180, bridge270)?
Or are you saying to do away with the prefab and have them script_brushmodels all in the same "level" of my map, non-prefabed?
thank you for your timely responses and for all the help so far . |
|
|
|
9837265498 |
|
General Member Since: Nov 6, 2009 Posts: 193 Last: Jan 23, 2012 [view latest posts] |
|
|
|
.KiLL3R. |
|
General Member Since: Oct 26, 2006 Posts: 1437 Last: Jul 3, 2017 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Tuesday, Jan. 25, 2011 01:56 am |
|
9837265498 writes...Quote:
Or do i make 4 different prefabs with different angle setting within the script_brushmodel (bridge0, bridge90, bridge180, bridge270)?
This :p |
|
|
|
9837265498 |
|
General Member Since: Nov 6, 2009 Posts: 193 Last: Jan 23, 2012 [view latest posts] |
|
|
Category: CoD4 Scripting Posted: Tuesday, Jan. 25, 2011 03:56 am |
|
i have a version of the prefab each with their differnt angles kvp's.
I have modified the script to this:
Code: main()
{
trigger = getentarray("drawbridge","targetname");
for(i=0;i<trigger.size;i++)
trigger[i] thread bridge_think();
}
bridge_think()
{
self.bridgemoving = false;
self.bridgeclosed = true;
self.bridge = getent(self.target,"targetname");
while (1)
{
self waittill("trigger");
if(!self.bridgemoving)
self thread bridge_move();
}
}
bridge_move()
{
self.bridgemoving = true;
if(self.bridgeclosed)
{
if(self.bridge.angles == 0)
{
self.bridge rotateroll(-90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = false;
}
else if(self.bridge.angles == 90)
{
self.bridge rotatepitch(-90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = false;
}
else if(self.bridge.angles == 180)
{
self.bridge rotateroll(90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = false;
}
else if(self.bridge.angles == 270)
{
self.bridge rotatepitch(90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = false;
}
else
{
}
}
else
{
if(self.bridge.angles == 0)
{
self.bridge rotateroll(90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = true;
}
else if(self.bridge.angles == 90)
{
self.bridge rotatepitch(90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = true;
}
else if(self.bridge.angles == 180)
{
self.bridge rotateroll(-90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = true;
}
else if(self.bridge.angles == 270)
{
self.bridge rotatepitch(-90,2);
self.bridge waittill("rotatedone");
self.bridgeclosed = true;
}
else
{
}
}
self.bridgemoving = false;
}
errors:
-on play the bridges are forced all to look at one direction regardless of their kvp's
-3 of the bridge dont do anything on trigger
-the 4th one, bridge0, rotates in the wrong direction
i get how to fix the 3rd (roll to pitch OR pitch to roll)
the other things are throwing me for a loop...
any ideas?
|
|
|
|