Jump to content

Rotation Wont Change on Physical Object


BrownBoxStudio
 Share

You are about to reply to a thread that has been inactive for 3261 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm creating a bow and arrow. I have a script that always has the arrow rotating so that the z axis is always facing in the velocity direction. The script works to set the rotation of the arrow but the script will not change the rotation if the arrow is physical. I'm not sure what I am doing wrong. Any help is appreciated. Thanks!

My script: 

default
{
    state_entry()
    {
        llSetTimerEvent(1);
        llCollisionFilter("Target", NULL_KEY, TRUE);
    }

    collision_start(integer total_number)
    {
        llSetStatus(STATUS_PHYSICS, FALSE);
    }
    timer()
    {
        rotation angleDif =  llRotBetween(llRot2Fwd(llGetRot()), llGetVel());
        rotation rot = llGetRot();
        
        //llOwnerSay((string) angleDif);
        llSetRot(rot+angleDif);
    }
}

 

Link to comment
Share on other sites

Problem may arise because llSetRot is not for physical objects

The wiki says about llSetRot(): This function is available for nonphysical root prims and all child prims. It has no effect on the root prim if the object is physical.


Take a look at llRotTarget() and the example to see how it can be done

Also notice if STATUS_ROTATE_X, STATUS_ROTATE_Y and STATUS_ROTATE_Z are set true
See llSetStatus() about how you do that

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

You maybe want to give this method below a shot.

Make the arrow a vehicle type airplane:

llSetVehicleType(VEHICLE_TYPE_AIRPLANE);

Adjust the reference frame if needed, to make the Z axis pointing in the direction of velocity.

llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, llEuler2Rot(<0.0,270.0,0.0> * DEG_TO_RAD));

Disable the linear and angular friction:

llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <10000.0, 10000.0, 10000.0>);llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <10000.0, 10000.0,10000.0>); 

Disable the linear deflection:

llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.0);llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 10000.0);

Set the angular deflection very strong:

llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 1.0);llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.001);

Add your collision filter. Make it physical and temp on rez.

llCollisionFilter("Target", NULL_KEY, TRUE);llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_PHYSICS, TRUE,  PRIM_TEMP_ON_REZ, TRUE]);

Add the collision event, and set physics, and temp to false when hitting the target.

collision_start(integer total_number){    llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_PHYSICS, FALSE,  PRIM_TEMP_ON_REZ, FALSE]);
}



  • Like 1
Link to comment
Share on other sites

If you want to point the Z axis of a physical object at something llLookAt is normally the way to do it, though I find llRotLookAt easier to work with.

However, I'm rather confused about why that's necessary in this case.   Maybe I'm missing something, but all the projectile weapon scripts I've seen, and certainly all the ones I've made, have the bow (gun, whatever) calculate the velocity direction when they rez the missile.    The script in the arrow simply tells it what to do when it collides with something.

I'd do something like this, in the bow:

//this is just a fragment and will not work on its ownfireProjectile(){		float velocity = 60.0;		rotation rot = llGetRot();		vector fwd = llRot2Fwd(rot);		vector pos = llGetPos()+fwd;		pos.z+=0.75;		fwd *=velocity;		llRezObject("arrow",pos,fwd,rot,99);}

ETA I've just looked again at the original posted script, and see that the timer event is firing once a second.   That's a very slow timer for a projectile.   Regardless of whether the code inside the timer works or not, I'd expect the arrow to have reached its target well before the timer fires (at least almost always -- since the timer event is running once a second, on very rare occassions it might be ready to fire just after the arrow is rezzed, but hardly ever).

Link to comment
Share on other sites

llRotLookAt rotates the object while it's physical so thanks for that. Except Iv'e learned my script to get the velocities angle doesn't work. 

The reason I have having the arrow rotate while moving is so that the arrow looks like the arrowhead is weighted. I want the arrowhead to always remain forward. 

Basically I want +z axis to always face in the direction that the arrow is moving. How can I go about doing that?

This is how I am getting the direction of Velocity. It doesn't seem to work and this is a bit over my head.

rotation angleDif =  llRotBetween(llRot2Fwd(llGetRot()), llGetVel());rotation rot = llGetRot();    llRotLookAt(rot+angleDif, 1.0, 0.4 );

 

 

Link to comment
Share on other sites

I still don't see why you're bothering with trying to rotate the arrow while its in flight.   It's an arrow, not a guided missile.   Assuming your arrow is based on a conventional tube -- that is, you want it travelling whatever way its positive z axis is pointing -- then simply rez it pointing the way you want it and off it should go.

Try this -- I've just tested it.

 

//This is just a fragment and will not work on its own    fireProjectile(){        float velocity = 60.0;        rotation rot = llGetRot();         rotation y90 = llEuler2Rot(<0.0,90.0,0.0>*DEG_TO_RAD);        // or, more simply, y90 = <0.00000, 0.70711, 0.00000, 0.70711>;        vector fwd = llRot2Fwd(rot);        vector pos = llGetPos()+fwd;        pos.z+=0.75;        fwd *=velocity;        llRezObject("arrow",pos,fwd,y90*rot,99);    }  

 

Link to comment
Share on other sites

If you are familiar with vectors it should be easy.

llGetPos() gives you the actual position of the arrow

llGetVel() gives you the velocity e.i. the speed and the direction the arrow moves

When you add the two you get a point somewhere ahead of your arrow and that is exactly what you want for llLookAt(): a point to look at.
It doesn't matter how far away the point is as long as it is ahead of the arrow in the direction of the movement

:smileysurprised::):smileyvery-happy:

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3261 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...