Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Reletive Vectors for Soccer ball script

Samantha Fuller
Registered User
Join date: 8 Sep 2006
Posts: 15
11-05-2007 23:32
I would like to create a script that would be open source or possibly sold for a realitvely small fee that would have the following properties
Onrez
2 hour countdown to die // to cleanup lost or abandoned balls
Setphysics TRUE;
bouency 75%
blockgrab // to prevent players or spectators from moving ball with cursor
Set touch text "Kick"
On Touch get key of toucher, do 1meter scan
If toucher is > 1m do nothing
If toucher is < 1m apply .25m/sec impulse recipical (away from)to direction of toucher.
If toucher is < .5m apply .5m/sec impulse recipical (away from)to direction of toucher and slightly up.
If toucher is < .25m apply 1m/sec impulse recipical (away from)to direction of toucher.
If toucher & another AV is < 1m apply impulse halfway between recipicals of bouth AV's possibly weighted for distance to allow for blocking and sideway kicking.

I'm pretty sure that i can manage most of it, but the realtive vectors, an hack would be to have the ball look at the touching AV then move backward along its axis but that woulden't creat the upword movement or sideways kicking in response to another av. :)
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
11-06-2007 08:27
I will help.

You can email me at [email]lee.ponzu@yahoo.com[/email], or post here.

Meanwhile, here is some logic...off top of head and not guarenteed...

vector ball = llGetPos();
vector kick = <position of the kicker>

vector direction = llVecNorm( ball - kick );


Comments...we need a way to allow the kicker to direct the ball in a desired direction, along with a random factor that depends on player skill...
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
11-06-2007 11:25
You can set a script at player prim shoes and check for collision no? Then you have the orientation, you can probably adjust left and right. The tough part would be the speed that would give the strength of the kick.
Samantha Fuller
Registered User
Join date: 8 Sep 2006
Posts: 15
11-06-2007 15:09
Twisted - i could create an attachment that fires very short range bullets at the ball compleat with animations, but for this project i want an simple easy to use single object system to encourage impromptu play. ie just rez ball and play :D

Lee - I want to avoid permmision to take controls if possible some RC cars use touch to take controls but i'm not sure if it's each player or the ball owner who would have to grant permision the first time each player "Kicked the ball, definitely the the owner would have to be in the sim, as i envisioned it the random factor that depends on player skill would be the vector to the second nearby AV who might be a teamate or not, which he would have to guestimate.
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
11-06-2007 21:54
You could set animations into the ball for kick jump anything you want. Then pop a menu when the player is close enough to the ball and animate the moves. The move will also decide the direction/strength of the kick.
Samantha Fuller
Registered User
Join date: 8 Sep 2006
Posts: 15
11-09-2007 23:33
Some of my first code on this project, it compiles, no error mesages but just dosen't work :o
CODE

// ***Soccor Ball Script***
// ***By Samantha Fuller***
// ***ver 0.3***
// ***11/9/2007***
float Buoyancy = .75;
integer Lifetime = 180; //# of minuets untill ball deletes itself
key Kicker;
key NearbyAV;
vector Kicker_Pos;
default
{
on_rez(integer Lifetime)
{
// set die timer to cleanup lost or abandoned balls
llSetTimerEvent(Lifetime * 60);
// to prevent players or spectators from moving ball with cursor
llSetStatus(STATUS_BLOCK_GRAB,TRUE);
llSetTouchText("Kick");
}
state_entry()
{
llSetStatus(STATUS_PHYSICS,TRUE);
llSetBuoyancy(Buoyancy);
}
touch_start(integer total_number)
{
Kicker = llDetectedKey(0); //grab key of Kicker(Toucher)
//do a short scan to tell which AV(s)are in range
llSensor("" ,NULL_KEY,AGENT,5,PI);
}
sensor(integer det_av)
{
float dist;
vector ball_pos = llGetPos();
dist = llVecDist(ball_pos, llDetectedPos(0));
if(det_av=0 && dist<1) //if Kicker(toucher) is < 1m
{
Kicker_Pos=llDetectedPos(0);
llLookAt(Kicker_Pos,1,.1); //orient ball to apply impulse
if (dist < 1)
{
//kick ball directly away from
llApplyImpulse(<-1,0,0>,TRUE);
}
else if (dist < 2)
{
//kick ball away & slightly up with less force
llApplyImpulse(<-0.5,0,.25>,TRUE);
}
else if (dist < 3)
{
//kick ball directly away eith even less force
llApplyImpulse(<-0.25,0,0>,TRUE);
}

}
}
timer()
{
llDie();
}
}
CODE
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
11-12-2007 07:34
I can't get in worl right now to try your football out but as a suggestion I would stick some llOwnerSay messages in there to help you debug.

Particularly to check the positional maths in the sensor to make sure it is producing the numbers you expect. You might also want to check the information of the Kicker (llDetectedPos(0)) to make sure it is getting the right information at all points as a lot seems to hang on the object sensing the kickers position.

I can see you get the kickers key

Kicker = llDetectedKey(0); //grab key of Kicker(Toucher)

but do you use this information in the script or is that being held back for something else.

Also have you tried applying the impules regardless of distance.

If I was building something like this I would have only one check and impulse to begin with until I had the physical behaviour down. Then I would introduce other conditions to vary the behaviour.
_____________________
Tread softly upon the Earth for you walk on my face.
Teddy Qinan
Registered User
Join date: 10 Mar 2007
Posts: 34
11-12-2007 20:31
If you are only having one ball on the field at a time, why not just make it physical? The people could 'kick' it by running in to it.