Help with a combat hit detection
|
|
Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
|
07-20-2006 12:17
Currently im making an RPG (Archer, Mage, Warrior) and i can only get the Archer and Mage to work because they fire objects at the monster. The Warrior obviously will be using a Sword and shield and the script i am using wont recognize this is the code for the collision: collision_start(integer det) { if (llGetAgentSize(llDetectedKey(0)) == ZERO_VECTOR && died != TRUE) { dmg = llFloor(llFrand(40)); attack = TRUE; attacker = llKey2Name(llDetectedOwner(0)); newhealth(llKey2Name(llDetectedOwner(0)), dmg, llDetectedKey(0)); llMessageLinked(LINK_THIS,1,attacker,""); llSetTimerEvent(attackspd); } }
Is there anyway i could get this to recognize whether it was an arrow or a sword? i dont want it to react when an avatar whacks it or you can just collide the monster to death...
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
07-20-2006 12:40
Don't know of a fast/efficient way. You could talk to the sword to see if it's there, if it's worn by the person you collided with, and so on. Sensors won't detect attachments, AFAIK, so that's probably out. Or have the sword talk every time it hits something... an attachment will pick up collisions of the wearer, I think. The sword could say something that tells the world about what it hit. And then the monster could listen for that, and see if it got hit, and if the chat matches, etc. This would be very chatty, since the sword might be constantly talking, especially if the av is walking on a prim floor. But it would avoid the 2-way communication needed if the monster queries the sword. So that's the tradeoff. Maybe you could get the sword to be intelligent about when it sends out its messages. Or use min event delay to slow down the sword's collision detection. But that would affect the overall response time of the game. Maybe something like 0.5s won't be noticable to the player. Rambling ideas... 
|
|
Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
|
07-20-2006 13:15
Still though having the sword detect a collision will be the same as the avatar walking into something so i could just collide my monster to death by walking into it without using the sword....
|
|
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
|
07-20-2006 13:20
I'm afraid that if you attach something, it effectively becomes part of you. You can't detect an attachment individually. You'll have to have the sword say something to the monster on collision. It can detect whether it has collided with a monster, and then say the monster's key on a particular channel, and the monster could hear that and decrement its hit points... as an example.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
07-20-2006 13:32
From: someone so i could just collide my monster to death by walking into it without using the sword I think I see what you're saying... you want the person to swing the sword, not just wear the sword and bump the monster. Then... maybe when he performs the 'swing' action (HUD, mouse click, whatever), you could have the sword scan for a monster. Maybe use a sensor cone that points the way the av is facing, and is just large enough to safely find a monster (I'm not sure if the sensor would run from the av's bounding box center? Don't know how that works when running a really tight sensor cone from an attachment). If the sword decides it's hit something (found a monster, it's in front, it's close enough, whatever else you need to take that decision), then it spits stuff out in chat, which the monster picks up, validates (yes its a valid sword on a valid player, yes it hit me, whatever), and does the health stuff. This requires a sensor scan each time the player 'swings', and a listener on the monster. Not *too* bad. Not passive, but I doubt this can be done passively.
|
|
Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
|
07-20-2006 13:42
Thanks for all the help, ill post what i did in the end, the sword does a sensor every time its swung on a cooldown relative to the sword quality. It broadcasts a message on a negative channel like this: attack,objectname,ownername,thekeyofthesense Then do CSV2List and the rest was easy from there 
|
|
Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
|
07-20-2006 13:44
From: Ziggy Puff I think I see what you're saying... you want the person to swing the sword, not just wear the sword and bump the monster.
Then... maybe when he performs the 'swing' action (HUD, mouse click, whatever), you could have the sword scan for a monster. Maybe use a sensor cone that points the way the av is facing, and is just large enough to safely find a monster (I'm not sure if the sensor would run from the av's bounding box center? Don't know how that works when running a really tight sensor cone from an attachment). If the sword decides it's hit something (found a monster, it's in front, it's close enough, whatever else you need to take that decision), then it spits stuff out in chat, which the monster picks up, validates (yes its a valid sword on a valid player, yes it hit me, whatever), and does the health stuff. This requires a sensor scan each time the player 'swings', and a listener on the monster. Not *too* bad. Not passive, but I doubt this can be done passively. Double post  Great minds think alike  thanks for the suggestions
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
07-20-2006 13:46
From: Ginge Reymont Is there anyway i could get this to recognize whether it was an arrow or a sword? i dont want it to react when an avatar whacks it or you can just collide the monster to death... The archer produces arrow when they shoot. In similar way, you could have the sword rezz a temporary full-alpha shape that matches width and angle of the swing, and test for collision vs that shape much like with arrow. Or could even texture it with 'blurry swoosh' sort of graphics to make swing more visually appealing, or something o.O;
|