My Shark ...
|
|
Tai Clifford
Registered User
Join date: 26 Jul 2006
Posts: 45
|
09-07-2006 15:23
Hi, I am building a shark to swim around my underwater area, at the moment it is a wooden box and it swims around, through my cave and back out. The script I am using is here:- //vector AXIS_UP = <0,0,1>; //vector AXIS_LEFT = <0,1,0>; vector AXIS_FWD = <1,0,0>; vector target; list targets = [ <237.50000, 12.83898, 19.68377>, <245.29184, 32.73343, 19.68377>, <248.82213, 54.01673, 19.61823>, <236.72945, 57.92976, 19.68377>, <224.24869, 58.84247, 9.62357>, <208.42651, 56.55777, 7.42540>, <195.01286, 41.13945, 7.18392>, <192.90558, 34.50874, 7.14464>, <194.04544, 23.65718, 7.16154>, <198.37169, 15.88624, 6.06457>, <194.06155, 9.64338, 5.86950>, <194.34900, 6.23267, 5.76467>, <198.07983, 3.47529, 5.68241>, <204.15303, 2.70814, 5.71122>, <211.14154, 6.95818, 5.51466>, <214.37660, 17.59837, 4.64921>, <224.89673, 12.50021, 1.48472>, <239.24303, 18.82541, 10.34873>]; integer place_num;
rotation getRotToPointAxisAt(vector axis, vector target) { return llGetRot() * llRotBetween(axis * llGetRot(), target - llGetPos()); }
float strength = 1.0; float damping = 1.0;
default { state_entry() { llSetStatus(STATUS_ROTATE_X,FALSE); llSetStatus(STATUS_ROTATE_Y,TRUE); llSetStatus(STATUS_ROTATE_Z,TRUE); llSetStatus(STATUS_PHYSICS, TRUE); llSetBuoyancy(1); llSetTimerEvent(0);
}
on_rez(integer param) { llResetScript(); }
touch_start(integer total_number) { llSetTimerEvent(10); }
timer() { target = llList2Vector(targets, place_num); //this is to help me keep track of it during testing llOwnerSay("Going to place "+(string)place_num+" target "+(string)target); llRotLookAt(getRotToPointAxisAt(AXIS_FWD, target), strength, damping); llMoveToTarget(target,5); place_num++; if (place_num >= 17) { place_num = 0; } }
}
My problem is that after doing a lap or 2 the box is no longer upright. It starts to roll around the x axis at some point and doesn't right itself. I thought that llSetStatus(STATUS_ROTATE_X,FALSE); would stop that from happening. Can anyone help me keep my shark vertical? If you have any other tips on how to improve this script I would also greatly appreciate it.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
Set Status ordering
09-08-2006 04:55
I think you need to set STATUS_PHYSICS first ? state_entry() { llSetStatus(STATUS_PHYSICS, TRUE); llSetStatus(STATUS_ROTATE_X,FALSE); llSetStatus(STATUS_ROTATE_Y,TRUE); llSetStatus(STATUS_ROTATE_Z,TRUE); llSetBuoyancy(1); llSetTimerEvent(0);
}
Not actually tried it, no SL atm, but all the physics code fragments I have do it in that order.
|
|
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
|
09-08-2006 18:10
Well, I played around with this for a bit...and I think I figured the problem...since it's still rotating on the Y axis, it appears that when it changes the Z axis the next point, part of that Y rotation translates to the X on its own somehow...
I have no idea how to explain it better than that....I got it to work for me by simply setting it not to rotate on X or Y and added a call after the look at rotation for it to tell me the rotation, and after several laps it remained at 0,0 for X and Y
|
|
Tai Clifford
Registered User
Join date: 26 Jul 2006
Posts: 45
|
09-08-2006 20:25
Thanks for your time looking at this, much appreciated.
|
|
Don Misfit
Registered User
Join date: 1 Jun 2006
Posts: 60
|
09-08-2006 23:43
Tai...
It is my understanding that llSetStatus(STATUS_ROTATE_X,FALSE); controls only the explicit rotation by script commands. Since the object is physical, however, it is still subject to other physical forces - such as rolling due to torque during a turn.
I have had the same problem with trying to do something similar to your shark - but with a stingray. It tends to roll, and if a "wing" clips another object (or underwater land mass) the ray just tumbles completely out of control.
Haven't found a good solution for it yet...
|
|
Tai Clifford
Registered User
Join date: 26 Jul 2006
Posts: 45
|
09-09-2006 00:38
So that my shark doesn't get too out of control I decided to kill it and rez a new one each lap of its track. Seems to work quite well so far. Just finished adding the final touches to the script, if you get too close to the shark it attacks and kills you, leaving a nice trail of blood in the water. Now I just have to make the actual shark, at the moment it is a wooden box roaming my waters  Then to make a spear gun to take revenge.
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
09-09-2006 03:30
altho i havent played with the shark ive been semi thinking about it ... could you reset the x axis to 0 apon checkpoint / timer or did i miss something
|
|
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
|
09-09-2006 14:11
I attempted to do that as well, it just didn't seem to work. As a secondary precaution, I have it set to phantom...so now it never gets off track since nothing can bump it
|
|
Tai Clifford
Registered User
Join date: 26 Jul 2006
Posts: 45
|
09-09-2006 14:13
From: Osgeld Barmy altho i havent played with the shark ive been semi thinking about it ... could you reset the x axis to 0 apon checkpoint / timer or did i miss something That would be the ideal thing to do. I am not exactly sure how to do it though. I have changed the code a bit now from the original, it doesn't have the timer event every 10 seconds, I now wait till I am near the target and then change rotation and move to the next target. If I could work out how to correct the roll in this llRotLookAt(getRotToPointAxisAt(AXIS_FWD, target), strength, damping); it would be perfect. Any ideas? I really appreciate everyones help.
|
|
Tai Clifford
Registered User
Join date: 26 Jul 2006
Posts: 45
|
My Shark and collision events
09-11-2006 00:25
The shark is progressing nicely, I have made it so it uses a sensor, if it detects someone within 5 metres of it, it rotates and moves towards them real fast. If there is a collision event with the person detected by the sensor it will give them 100% damage effectively killing them and leaving a trail of blood in the water.
Which leads me to my next problem which I am not sure how to solve. I am going to make a speargun to shoot it with. I want to be able to shoot the shark, but I need the shark to know when it has been shot and by whom. Can anyone see a way that I can make the shark know it has been shot and who shot it? There may be more than one person with a spear gun and I want to run a point score system for a competition.
Any thoughts, suggestions would be greatly appreciated.
|
|
Vares Solvang
It's all Relative
Join date: 26 Jan 2005
Posts: 2,235
|
09-11-2006 00:51
It seems to me like it would be easier to put the hit detection script into the spear head. Some kind of collision detector that will send a message to whatever scoring system you are using. That should make it pretty easy to identify the person that hit the shark.
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
09-11-2006 01:01
The same collision event should work - you can detect the type thing causing the collision, and the various llDetected* functions work in collision events too.
So... llDetectedType() for av or object, llDetectedName() will let you check it's a spear and not a rock or similar. llDetectedOwner() will let you see whose spear it was.
|
|
Tai Clifford
Registered User
Join date: 26 Jul 2006
Posts: 45
|
09-11-2006 15:11
From: Vares Solvang It seems to me like it would be easier to put the hit detection script into the spear head. Some kind of collision detector that will send a message to whatever scoring system you are using. That should make it pretty easy to identify the person that hit the shark. That is a good suggestion, but I also need the shark to know when it has been speared too. From: Eloise Pasteur The same collision event should work - you can detect the type thing causing the collision, and the various llDetected* functions work in collision events too.
So... llDetectedType() for av or object, llDetectedName() will let you check it's a spear and not a rock or similar. llDetectedOwner() will let you see whose spear it was. Wow .. that should make it really easy to determine. Time for some more experimenting, thanks. 
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
09-11-2006 15:58
A tip to avoid some potential frustration, because I've forgotten this and made the same mistake multiple times  llDetectedType returns a bitmask. So don't use if (llDetectedType(i) == AGENT) Because that is likely to return false, since most avatars are AGENT|ACTIVE, and if you're wearing a scripted attachment, you're AGENT|ACTIVE|SCRIPTED. Or something like that. Either way, the point is, you should use if (llDetectedType(i) & AGENT) instead. And if you want the shark to be phantom, use llVolumeDetect, which lets you turn an object phantom but still pick up collisions.
|
|
Tai Clifford
Registered User
Join date: 26 Jul 2006
Posts: 45
|
09-11-2006 22:49
Thanks for the tips Ziggy. This is so much fun playing with this stuff. Haven't made my speargun yet, but I have been shooting it with a revolver. It was quite easy to get it all to work. For some reason I had to move the script that accesses the dataserver and gets the owners name using their key, into another script and call it with a linked message. When I had it in the same script it wasn't working. Now the shark says who killed it before it dies. To add to the fun I am going to make it so you have to surface to reload the speargun. Gotta give the shark, and eventually a heap of fish, a fighting chance.
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
09-12-2006 05:09
From: Tai Clifford For some reason I had to move the script that accesses the dataserver and gets the owners name using their key, into another script and call it with a linked message. When I had it in the same script it wasn't working. Now the shark says who killed it before it dies. You can probably simplify that bit using just llKey2Name() call instead of dataserver lookup. Key2Name() will work only if the AV is in the same sim, but it generally shouldn't be a problem for this kind of shark hunting activity ^^;
|
|
Tai Clifford
Registered User
Join date: 26 Jul 2006
Posts: 45
|
09-12-2006 15:34
From: Joannah Cramer You can probably simplify that bit using just llKey2Name() call instead of dataserver lookup. Key2Name() will work only if the AV is in the same sim, but it generally shouldn't be a problem for this kind of shark hunting activity ^^; Thanks Joannah, I didn't know about that one.
|