How to trigger an enemy actuator with a ray from the player?

I want a target (image) showing up on enemies which i look at.

Problem with current solution:
The mouse over actuator doesn’t work very well past 10 units distance between the player/camera and the enemy (especially from the top).

I was wondering if there was any other way to do this so that it would also work for long distances?
Just from thinking about it messages won’t work as they will trigger the image on all enemies at once.

any usable solutions would be greatly appreciated

Thanks:D

property in enemy

target=Ray.hitObject
scene=bge.logic.getCurrentScene()
scene.addObject(“HighLight”,target,1)

steaming hot example file :smiley:

fresh from the oven

To trigger a actuator though

in object to be triggered
if Prop=1----------and---------Actuator
___________________--------Prop=0

and use
and in triggering object
Ray------------python

import bge

cont=bge.logic.getCurrentController()
own=cont.owner()
sens= cont.sensors[‘Ray’]
target=sens.hitObject
target[‘Prop’]=1

Ray highlight 2 = both scripts rolled into one

Attachments

RayHighLight.blend (450 KB)RayHighLight2.blend (452 KB)

Awesome thanks BluePrint I’ll see what i can do with it!

Ok just one problem at the moment, how would you activate an actuator through this? i always get an error

The original script:

import bge
from bge import render

def main():

cont = bge.logic.getCurrentController()
own = cont.owner

sens = cont.sensors[‘Ray’]
scene=bge.logic.getCurrentScene()

if sens.positive:
render.drawLine(own.worldPosition,sens.hitPosition,(255,0,0))
scene.addObject(“HL”,sens.hitObject,1)

main()

Please use code tags when posting code.

You activate an actuator when the event to activate it occurs. To determine the event use sufficient sensors and controllers.

Actuators are ONLY activated from connected controllers. Everything else is bad design leading to logic that is impossible to maintain.

So what o you want to do. I do not see an actuator in your code snippet. If you mention errors you should post the error too.

Btw.:
Please throw away this useless “main”. You are not coding a standalone application. Use a meaningful name like “drawLaser”.

no Monster in script mode you have already the name on the script, drawLaser -> drawLaser, … code redundant :smiley:

Maybe you confuse it with “drawLine” which is an attribute of module bge.render.

Function names have no relation to script mode or module mode. The only relation is that you need the function name when configuring the Python controller in module mode.

As I do not really know what Thatimster is going to do I suggest to call the combination of drawn line + addedObject a “laser” which gives “drawLaser” a meaning. Thatimster can call it as he like. Even “performTheMikeyMouseDance” would be sufficient (beside the fact it is obviously not correct). To be honest it would have more value than “main”. Unfortunately I do not know what a “main” is in the context of the BGE.

Ok so adding this to the script:

if sens.positive and (2nd input).positive:
cont.activate ['State']

caused a subscript error in the console using both module and script mode.

Just to be clear i’m not actually using the drawline function in game.
As irrelevant as the name “main” might be, it has nothing to do with the problem at hand (no offence intended), so instead of turning into a big rant like every 2nd thread on BA can we please focus on the topic at hand. I would appreciate it:D.

From my understanding when the players ray hits an enemy it spawns an object (on the enemy). I want to then change the state (on the player) which then goes to an attack state.

Any little snippets of code which i could substitute in or explanations on why its not working and how i can fix it would be greatly appreciate it:D!

ok I need your full code,

the problem is your definition of sensor 2 I think

lets see :smiley: