A Number Of Ray Sensor Improvements
Closed, ArchivedPublic


Added additional python methods to the ray sensor.


Here is an excerpt from the KX_RaySensor.py explaining what each does.

def setRange(range):
Sets how far the ray casts, in blender units.

@param range: How far the ray should cast
@type range: number
def setAxis(axis):
Sets which axis for the ray to cast on.
0,1,2 = X,Y,Z accordingly.
3,4,5 = -X,-Y,-Z accordingly.

@param axis: Which axis the ray should cast on
@type axis: number
def setProperty(property):
Set the ray to look for objects with the property of (property).

@param property: What property to look for
@type property: string
def setMaterial(material):
Set the ray to look for objects with the material of (pmaterial).

@param material: What material to look for
@type material: string
def setVector(x,y,z):
Sets the say to cast along the vector of x,y,z instead of constrained to an axis.
def recast():
Recasts the ray immediately, so you can do changes on property,axis,range whatever and then cast again multiple times a frame.
def setMaxHits(maxHits):
Enables the ray to hit multiple objects/positions per raycast up to (maxHits) default is 1.

@param maxHits: Maxmimum hits per cast
@type maxHits: number
def seeThroughUnmatched(seeThrough):
If (seeThrough) is true then the ray will see through objects that do not match the property or material
instead of stopping at them or counting them towards max hits.

@param seeThrough: Whether or not to hit unmatching objects.
@type seeThrough: number or boolean
def getHitObjectList():
Gets a list of objects hit by this ray closest first.

@return: A list of the objects hit
def getHitPositionList():
Gets a list of positions hit by this ray closest first.

@return: A list of the positions hit
def getHitNormalList():
Gets a list of normals hit by this ray closest first.

@return: A list of the normals hit
def getNumHits():
Gets how many things were hit by this ray.

@return: How many things were hit

This makes it way easier to make more advanced games like shooters, shooting though glass, using rays for accurate bullet collisions is made very easy by this with other things as well. Makes it possible for rays to hit multiple objects or see through objects that do not match the property/material and casting the ray along any vector instead of being fixed to an axis.

Mitchell Stokes (moguri) lowered the priority of this task from "Normal" to "Low".Via WebJul 1 2014, 6:31 AM

This type of functionality seems better suited to the raycasting API (KX_GameObject.rayCast/rayCastTo()). If this is something you still want reviewed (kind of doubtful after 6 years), please add it to Differential.

Mitchell Stokes (moguri) closed this task as "Archived".Via WebJul 11 2014, 8:50 AM

Add Comment