diggerjohn4 Posted May 26, 2011 Share Posted May 26, 2011 I am trying to develop a Coin Toss.I was just wondering if anyone knows of existing script/behavior for this they can point me too.Just trying to avoid re-inventing the wheel here if I can.Thanks .... Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted May 26, 2011 Share Posted May 26, 2011 Look at the examples for llFrand. Link to comment Share on other sites More sharing options...
diggerjohn4 Posted May 26, 2011 Author Share Posted May 26, 2011 Very cool, thank you. But I still need to actually flip the coin. Link to comment Share on other sites More sharing options...
Rolig Loon Posted May 26, 2011 Share Posted May 26, 2011 The basis for a simple coin toss game will be the llFrand function, with which you can generate a random number. In this case, since you're looking foir either a 0 or a 1, you'll want to build around integer Coin_Flip = llRound(llFrand(1.0)); The rest of your script is just packaging. Link to comment Share on other sites More sharing options...
diggerjohn4 Posted May 26, 2011 Author Share Posted May 26, 2011 This is also very helpful, thank you. Perhaps I should have said "Coin Flip". I am still working on getting the coin flipped physically. Link to comment Share on other sites More sharing options...
Rolig Loon Posted May 26, 2011 Share Posted May 26, 2011 llApplyRotationalImpulse(<0,0.5,0>,TRUE); You'll want to scale that to the mass of your coin so that it doesn't flip it into the next sim. Link to comment Share on other sites More sharing options...
diggerjohn4 Posted May 26, 2011 Author Share Posted May 26, 2011 Thank you. This gets me on the path. Link to comment Share on other sites More sharing options...
Rolig Loon Posted May 26, 2011 Share Posted May 26, 2011 Good. From there it's pretty easy. :smileyhappy: At least while you are testing, I suggest building a failsafe into your script to keep track of where the flipped coin went. Physical objects have a way of vanishing in a flash if you zap them with too much force. You can lose stuff quickly (and annoy your neighbors). I like creating a simple homing routine on a two-second timer. If the coin is more than X meters away when the timer fires, the object goes non-physical and comes home. Link to comment Share on other sites More sharing options...
diggerjohn4 Posted May 26, 2011 Author Share Posted May 26, 2011 Ah yes, case in point. What I need to do is keep this coin from going away. I am trying to get it to go straight up and down. So I need to restrict its natural parabola. Not sure how just yet. I assume that the homing device works off of llGetPos to get the current/initial postion and then using llSetPos to put it back. Link to comment Share on other sites More sharing options...
Rolig Loon Posted May 26, 2011 Share Posted May 26, 2011 It's not easy to make a physical object follow a predicatable path, so good luck getting it to go straight up and down. If you don't overdo the flip, though, it won't go far. llSetPos has a 10m limit, so it's not much good for catching something that takes off halfway to the Moon. You'll have to use WarpPos or PosJump. Try something like safe_posJump(vector target_pos){ vector start_pos = llGetPos(); llSetLinkPrimitiveParamsFast(!!llGetLinkNumber(), [PRIM_POSITION, <1.304382E+19, 1.304382E+19, 0.0>, PRIM_POSITION, target_pos, PRIM_POSITION, start_pos, PRIM_POSITION, target_pos]); llResetScript();}vector Home;default{ state_entry() { llSetStatus(STATUS_PHYSICS,TRUE); Home = llGetPos(); } touch_start(integer num) { llSetTimerEvent(3.0); llApplyRotationalImpulse(<0.0005,0.0005,0>,TRUE); } timer() // This is your safeguard, just in case the coin gets away. { if (llVecDist(llGetPos(),Home) > 10.0) { llSetStatus(STATUS_PHYSICS,FALSE); safe_posJump(Home); } }} 1 Link to comment Share on other sites More sharing options...
diggerjohn4 Posted May 26, 2011 Author Share Posted May 26, 2011 Wow, fantastic .... thank you, I will give this a shot. Link to comment Share on other sites More sharing options...
diggerjohn4 Posted May 26, 2011 Author Share Posted May 26, 2011 I have tweeked your code ever so gently and I think I am just about there. Now I have the concept, application is just around the corner. Thank you so very much. Link to comment Share on other sites More sharing options...
Frances Meriman Posted June 16, 2011 Share Posted June 16, 2011 I have my coin flip going ok now. Just wondering now how to insure which side is showing after the flip. In other words I need to rig it so I know what the result will be. Actually I want to determine the result. Any ideas? Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 16, 2011 Share Posted June 16, 2011 You can't predict which way the coin will land because that's all up to the physics of the toss. You can use this idea to tell which end is up after the fact, though ...... default{ touch_start(integer total_number) { vector Up = llRot2Up(llGetRot()); if (Up.z > 0.0) { llSay(0, "heads"); } else { llSay(0,"Tails"); } }} Instead of putting it in a touch_start event, you could trigger it with a timer a few seconds after the toss (so that it has time to bounce a few times and come to rest). Record the result in a list or whatever you want to do. Now, you could always use this as a way to bias the outcome, I suppose. If the coin lands with tails, for example, you could script it to flip again gently one time, thus biasing the result toward heads. If that's what you meant by "rigging" the coin, you never heard me suggest it. Link to comment Share on other sites More sharing options...
diggerjohn4 Posted June 16, 2011 Author Share Posted June 16, 2011 Yes of course. Maybe what I could do is change the texture, once I know what side it has landed on, to reflect the the side I wanted it to be. I want to try to hide the fact I am rigging the result of course as much as can be done. Thank you ... BTW, your by line troubles me but I get it. You certainly are not dumb and I sincerely doubt you look it either. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
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