Author Topic: Static shape rotation  (Read 1009 times)

I am making a bomb that you plant on a wall using an edit of the sticky bomb launcher for use in my server. The problem is, the static shape that sticks to the wall always faces the same direction. No matter where I put it. I want it so it will face away from the wall you planted it on. Here is the plant code.
Code: [Select]
function Projectile::spawnC4Bomb(%obj,%col,%fade,%pos,%normal)
{
%type = %col.getType();
if((!(%type & $TypeMasks::fxBrickObjectType) && !(%type & $Typemasks::StaticObjectType) && !(%type & $TypeMasks::TerrainObjectType)))
return;

if(%col.getType() & $TypeMasks::StaticShapeObjectType && %col.getDatablock() == C4Static.getID())
return;

%player = %obj.client.player;
if(!isObject(%player))
return;

if(!isObject(%player.C4BombSet))
%player.C4BombSet = new SimSet();

%pos = vectorAdd(%pos,vectorScale(%normal,0.15));
%rot = rotFromTransform(%obj.getTransform());
%scaleFactor = getWord(%obj.getScale(),2);

%s = new StaticShape()
{
dataBlock = C4Static;
position = %pos;
rotation = %rot;
normal = %normal;

client = %obj.client;
sourceObject = %obj.sourceObject;
fireTime = %obj.fireTime;
};
MissionCleanup.add(%s);
%s.setScale(%scaleFactor SPC %scaleFactor SPC %scaleFactor);
%player.C4BombSet.add(%s);
%s.set = %obj.C4BombSet;

if(isObject(%player.client))
{
if(isObject(%player.client.minigame) && %player.client.tdmTeam != -1 && %player.client.tdmTeam !$= "")
%col = getColorIDTable(%player.client.minigame.teamCol[%player.client.tdmTeam]);
else
%col = %player.client.chestColor;
}
else
%col = "1 1 1 1";
%s.setNodeColor("ALL",%col);

%obj.schedule(33,delete);
}

The code would be pretty advanced. But you ever need to work it out from the normals (how the face the object collided with projects out, 0 0 1 means the face is facing up, 1 0 0 means facing east etc. Or you could somehow invert the colliding rotation of the projectile, like if the c4 projectile was going forward you invert it to sit backwards on the face.
EDIT: I'd also like to point out that you shouldn't really be using a projectile to place it, you should be doing a raycast for where the player is looking when they fire the weapon.
« Last Edit: February 20, 2010, 11:59:47 PM by Destiny/Zack0Wack0 »

So the code just for the rotation would be stuff long. I only want it to align with the brick grid, north south east or west.

I also heard that the max schedule time is 30000. I want to make it so it waits 5 minutes before deleting.
Code: [Select]
%s = new StaticShape()
{
dataBlock = VehiMineStatic;
position = %pos;
rotation = %rot;
normal = %normal;

client = %obj.client;
sourceObject = %obj.sourceObject;
fireTime = %obj.fireTime;
};
MissionCleanup.add(%s);
%s.schedule(30000,delete);

I also heard that the max schedule time is 30000. I want to make it so it waits 5 minutes before deleting.
False.
That is only for events.

For 5 minutes, do 300000.

If I remember correctly, Amade tried to do this for his elemental rock thing. I just downloaded the latest version from RTB and read it:
Code: (Stone.cs) [Select]
%spike = new TSstatic()
{
datablock = StoneSpikeData;
shapeName = "Add-Ons/Weapon_ElementalSpells/OtherShapes/StoneSpike.dts";
position = %pos;
rotation = "0 0 0 0";
scale = %scale;
};
If he ever figured it out, he never updated the add-on, but it's still probably worth asking him.

I never did manage to get it figured out. I tried every conversion function I could find but none of them worked correctly.

the only good way would  probably be making a c4 brick with a dts shape like the ammo crate. Then placing it using raycasts like the trench mod

Well if it's a brick it'll always be pointing straight up and you're confined to the brick grid, both in position and rotation.

Yea, but it can still rotate 90 degrees. This seems way complicated for something that should be so simple.