Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Why does it turn back when I hit it by llApplyImpulse

Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
11-20-2006 03:12
Hello there, I'm messing up my football shooting game. :(

I made this script to see how llApplyImpulse worked.
The ball catches avatar by senseor and aims by llLookAt.
Then I wanted to hit it a long way by llApplyImpulse.
It flew in the direction of my expectation but I got it turn back to the position where I hit immediately. :confused:
Anyone helps?

CODE
vector force = <-10, 0, -30>;
vector offset;

offsetByAVSize(key Agent)
{
vector AVSize = llGetAgentSize(Agent);
offset = <0.8, 0, 1.0 - AVSize.z>;
}

default
{
state_entry()
{
llSensorRemove();
llOwnerSay("state default"); //Info for Debug
llSetStatus(STATUS_PHYSICS, TRUE);
}
on_rez(integer reset)
{
llResetScript();
}
collision_start(integer num_detected)
{
llSensorRemove();
lllSensorRepeat("","",AGENT, 2, PI, 0.2);
}
sensor(integer total_number)
{
offsetByAVSize(llDetectedKey(0));
vector pos = llDetectedPos(0);
llMoveToTarget(pos+offset*llDetectedRot(0), 0.2);
llLookAt(pos + <0, 0, offset.z>, .1 , 1);
}
no_sensor()
{
llSensorRemove();
}
touch_start(integer total_number)
{
llSensorRemove();
llStopLookAt();
state shooting;
}
}

state shooting
{
state_entry()
{
llOwnerSay("state shooting"); //Info for debug
llApplyImpulse(force, TRUE);
llSleep(3);
state default;
}
}
_____________________
:) Seagel Neville :)
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
11-20-2006 10:53
The reason it comes back is that the llMoveToTarget() is still in effect when you call llApplyImpulse.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
11-20-2006 11:06
I assume you want the sensor so the ball keeps moving in front of the av while he runs behind it, until someone else bumps into it? Some suggestions:

* If you ever play this on a prim field, you'll get collisions with the field itself (I ran into that with a game I made). The solution - in the collision handler, search through the Detected* functions and make sure that you're dealing with an av collision:

CODE
(llDetectedType(i) & AGENT) == AGENT


I also set up a slower event delay, say 1s or 2s, or you'll get flooded with collision events if the ball's on a prim floor.

* Instead of running a sensor, you could just apply an impulse on collision? That way the player has to keep 'kicking' the ball (by running into it). And then you don't need to set a target either, so the shooting should work as well. But I don't know if the mechanics of this will work well or not, maybe you tried it already. If you need to use Move2Target, then like Lex said, remove the target before you shoot.
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
11-20-2006 14:27
Aha! Thank you, Lex. I didn't notice it. :D
And Ziggy, thank you for the informative suggestions. I'll give it a try. :)
_____________________
:) Seagel Neville :)