Jump to content

Script Help


QueenofChaos26
 Share

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

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

Recommended Posts

I'm making these throwing knives that rotate using PRIM_OMEGA as they soar through the air and I'm wanting them to stick to what they hit. So by doing that, I thought i'd change the physics of them as well as the rotation when they collide. My code is as followed:

default
{
    state_entry()
    {
        llSetPrimitiveParams([PRIM_OMEGA, <0,0,2>, 10, 1]);
    }

    collision(integer num_detected)
    {
        llSetPrimitiveParams([PRIM_OMEGA, <0,0,0>, 10, 1, PRIM_PHYSICS, FALSE]);
        llSetTimerEvent(10);
        }
    
    }

However, when it hits an object, it just bounces off them and it doesn't stop spinning. How do I fix this?

Link to comment
Share on other sites

You have a couple of challenges.  llSetStatus isn't supposed to have a forced delay, but it does have one in practice.  Remember that server activity proceeds in frames, 45 times a second.  An object can travel a fair distance in that short time, so getting the timing right fo making your knife physical isn't easy.  The other challenge is that your spinning knife needs to arrive at the target point first or it will look silly if/when it really does stick.  

You might try a rather complicated approach.  Schematically,

1. Before you "throw" the knife, identify the target and the distance to it.

2. Make the knife physical and throw it, with spin.

3. When the knife is within some reasonably small distance of the target, 

4.  Make it stop spinning

5. Make it non-physical.

6. Rotate it so it's pointing to the target.

7. Move it the rest of the way with llSetRegionPos.

If the target is moving or if you have some other compelling reason, you  can have the knife run a fast timer to update the target's position and adjust when it has arrived at step #3.

Link to comment
Share on other sites

try changing the prim physics state in collision_start

typically what we do with thrown objects in collision_start

1) 1st line of code get the X,Y,Z position of the object

2) 2nd line of code, change the physics state, and any visual spin effects

3) 3rd line of code, re-position the now non-physics object at X,Y,Z (to ameliorate drift because client side lag), and rotate the thrown object so is relative to the target

edit: or what Rolig said :)

 

Edited by Mollymews
or rolig
Link to comment
Share on other sites

I had a similar problem a while back. One solution that was offered was to perform a series of short-range ray casts to "look ahead" and predict any incoming impacts.

Reference:

 

Edit: additionally, I played around with some of the prim's properties to reduce it's elasticity. That may also help to dampen the bounce on contact.

Edited by Fenix Eldritch
  • Like 1
Link to comment
Share on other sites

2 minutes ago, Mollymews said:

try changing the prim physics state in collision_start

typically what we do with thrown objects in collision_start

1) 1st line of code get the X,Y,Z position of the object

2) 2nd line of code, change the physics state, and any visual spin effects

3) 3rd line of code, re-position the now non-physics object at X,Y,Z, and rotate the thrown object so is relative to the target

ok say what now?

 

4 minutes ago, Rolig Loon said:

You have a couple of challenges.  llSetStatus isn't supposed to have a forced delay, but it does have one in practice.  Remember that server activity proceeds in frames, 45 times a second.  An object can travel a fair distance in that short time, so getting the timing right fo making your knife physical isn't easy.  The other challenge is that your spinning knife needs to arrive at the target point first or it will look silly if/when it really does stick.  

You might try a rather complicated approach.  Schematically,

1. Before you "throw" the knife, identify the target and the distance to it.

2. Make the knife physical and throw it, with spin.

3. When the knife is within some reasonably small distance of the target, 

4.  Make it stop spinning

5. Make it non-physical.

6. Rotate it so it's pointing to the target.

7. Move it the rest of the way with llSetRegionPos.

If the target is moving or if you have some other compelling reason, you  can have the knife run a fast timer to update the target's position and adjust when it has arrived at step #3.

im sorry but huh?!

 

Link to comment
Share on other sites

Molly and I are proposing similar versions of the same idea.  Basically, make the knife non-physical when it's near the target and do the last bit of rotating it and sticking it as a non-physical object.  Fenix's method looks intriguing as a way to do that last bit of rotating the knife point-forwards.

Link to comment
Share on other sites

the numbered steps shown by myself and Rolig, are the algorithms

given a algorithm then we translate it to the language we are using.  To do a translation to LSL then we look up the words we need on the wiki

example look ups:  collision_start. llGetPrimitiveParams, llSetPrimitiveParams

Link to comment
Share on other sites

I still dont know how to do any of that stuff. I went to llsetregionpos page on wiki and that helped me none. I hate when ppl try to help and I dont even understand what they are telling me. The stuff ik how to script I had figure out on my own and even that nearly caused me to rip my own hair out. I probably should just stop scripting and hire ppl to do it for me cause nothing in the post has made any sense to me.

Link to comment
Share on other sites

try not to get discouraged Queen. Just keep persevering, learning and understanding a little bit each time

i often feel the same whenever I open Blender, yet I can whiz stuff up with inworld prims without having to think about it much at all. It just takes time to learn

what I think can hinder us in learning is that we sometimes jump to quite complex projects (which on the surface can seem quite simple) without learning and practising all the 101 stuff first.  Throwing a physical object and having it stick to a target is not a trivial piece of code.  This kinda code can often be quite short when written, but there is a lot going on: rotation, physics, flight, collision, positioning, raycasting, etc.  So we have to learn what all these mean and come to understand them thru practice

  • Like 1
Link to comment
Share on other sites

Perhaps it would be prudent to take a few steps back and try to shore up your foundational knowledge. Being familiar with the basic concepts of LSL (and programming in general) will be essential as your progress in your scripting projects. Topics and concepts very quickly build upon each other and if you don't have a good grasp on the basics, it will make anything even remotely more advanced difficult. That includes reading documentation like the various LSL function pages on the wiki.

If you haven't already, I would wholeheartedly recommend you take some time and read through the tutorials on the wiki. Read through them in order, and they will introduce you to all the basics and you can build up from there.

http://wiki.secondlife.com/wiki/Category:LSL_101

And you can always ask questions that arise along the way and we'll try to answer as best we can. Good luck!

Edited by Fenix Eldritch
  • Like 1
Link to comment
Share on other sites

Molly and Fenix are making good suggestions We all started at ground zero once, just like you.  I remember working for what seemed like days to make a script that would change a prim from red to green and back again, over and over. Patience and persistence are your friends.  Start with small, simple tasks that won't require any fancy functions.  That way, you can focus on the logic instead of the language.As a rule, scripted things that move are tougher than things that stand still.So, see if you can make a prim change color from red to green and back, over and over again. Then see if you can make it move back and forth. Then ....

  • Like 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1779 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...