Jump to content

Kicking a ball


Physiker
 Share

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

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

Recommended Posts

Hi

I want to make a script to kick a ball, or shoot on target in soccer. I know it's simple, I tried it but it doesn't work. It seems to apply the impulse, but after that the ball suddenly returns to it's original position. I used the function llApplyImpulse(<5,0,0>,TRUE);

Can you help me what's wrong, or post a working script? Thank you.

Link to comment
Share on other sites

As Darkie says, it sounds like something else in your script that's causing the problems.   Here's a very basic script that works for me -- just tested it:

default {  state_entry () {    llSetStatus (STATUS_PHYSICS, TRUE); // make sure that Physical is turned on      }    collision_start (integer total_number) {    llSay (0, "Collided with "+llDetectedName (0));    llApplyImpulse (<2, 0, 0>, FALSE);      }}

 

ETA -- there's a tutorial on making a kickable ball at http://www.ibm.com/developerworks/rational/tutorials/r-radsl/section3.html  (the first two sections you can skip -- it's all about how to install Eclipse and stuff -- and the interesting stuff starts at that link).

Link to comment
Share on other sites

integer communicationChannel = 7779;vector direction;default{    state_entry()    {        llOwnerSay("running");        llSetRemoteScriptAccessPin(69);        llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);        llSetStatus(STATUS_PHYSICS, TRUE);        llListen(communicationChannel, "", NULL_KEY, "shoot");        llSensorRepeat("",NULL_KEY,AGENT,1.5,2*PI,.5);  //check whether the ball is close            }    sensor(integer total_number)    {           vector pos = llDetectedPos(0);        vector unit = <1,0,0>;        vector offset;        offset=(unit * llDetectedRot(0));   //rotate vector unit        pos+=offset;        direction=offset*6;                 //set direction of the kick in the bottom        llMoveToTarget(pos,.1);          }      listen(integer channel, string name, key id, string message)    {               llOwnerSay("now shooting");     llApplyImpulse(direction,TRUE);            //kick the ball    }}

 

If if I'm not in posession (futher away than 1,5 meters), I try to kick it, the ball moves, but goes back to it's original place, it shouldn't do that as I'm far away, so the event sensor doesn't get triggered. What's the problem with this scipt?

Link to comment
Share on other sites

Of couse it does - it still gets your command and the listener receives it - you just don't set the new 'direction' since the sensor doesn't get triggered.

To avoid this, you could introduce a global integer which gets set to true if there is an Agent close by. The listeners only kicks the ball if the global is true.

if no_sensor is fired, set the globalö to false.

Another maybe more elegant way would be to check the distance in the listener before kicking.

Link to comment
Share on other sites

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