Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

bow and arrow

Kaige Tokhes
Registered User
Join date: 15 Mar 2006
Posts: 11
05-23-2006 14:38
I get all the gun scripts and understand somewhat what is going on in most of the free ones. The one thing i cant understand it how to rez an object and make it fly the correct way. All the things i have tried to do this with have rezzed sideways and after looking through the free scripts and looking up the rezobjects and getrot and rez2forward i am lost. could anyone please explain if it has to do with the parent prim of the arrow or the rotation when i add it to the bow. I have triued all i can but i am still reading as we speak
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
05-23-2006 17:52
Could you make the arrow a physical object and give it a push and rotation?

Not sure how you would make the bow change shape though.

Ed
Deneb Rosewood
Registered User
Join date: 2 Feb 2006
Posts: 15
05-24-2006 02:12
I've been playing with this recently, and lemmy just warn you first; it's a pain in the-...

The llRezObject code you use to fire the weapon can set the rotation, generally sence math to rotations is impossable, llGetRot() is the way to go (it returns whatever dirrection your facing, perfect because you want it to face that way)

HOWEVER!!! The true terror of this story is that you have to make the arrow in perfect accordence to ZERO_ROTATION! Oh the horror... Because I can't figure out which way is forward!!! My throwing knife script will never be complete because I gave up trying to make the knife. Do I make it face up? North? East? Dunno! But two of my tries ended in failure.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
05-24-2006 02:38
Forward is the positive X-direction i.e. the way that the red arrow is pointing if you edit in "World" mode.

However, you can set the rotation to anything you want when you rez the object. Say your arrow is pointing up (positive Z direction) - all you do is apply a rotation of 90 degrees aroung the Y-axis to the value of llGetRot each time.

e.g.
CODE

rotation gTurn;
float gSpeed = 40.0;

...

state_entry()
{
gTurn = llEuler2Rot(<0.0, PI_BY_TWO, 0.0>);
...
}

...

// your firing routine
vector pos = llGetPos();
rotation rot = llGetRot();
vector fwd = llRot2Fwd(rot);
llRezObject("Arrow", pos, rot * gSpeed, gTurn * rot, 1);

...


(in practice though it's quicker and easier just to make sure your projectile's forward direction is along the X-axis)
Kaige Tokhes
Registered User
Join date: 15 Mar 2006
Posts: 11
ok i got it but i have a new question
05-24-2006 08:45
I found that if you use a prim where the "local" red axis whatever that is is pointing in the direction you want it will fly straight. what i cant figure out is how to rotate that for an object that rez'swith that in the middle. say a cone, the red arrow is always in the middle so it will always fly sideways. i guess there is a way to rotate this but i being a bad programmer will have to play a lot more with it
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
05-24-2006 08:50
You have to use something like the code I posted above, to turn the object in the right direction when you rez it. You can't change the direction of the red arrow, not for a single prim anyway.