scaling problem

solarlunes script is not working.It is supposed to scale a cube until it hits a cube with a particular property.

from bge import logic

cont = logic.getCurrentController()
obj = cont.owner
sce = logic.getCurrentScene()

track = cont.actuators['Track']

if not 'laserinit' in obj:                          # Quick object set-up
    obj['laserinit'] = 1
    obj['dest'] = sce.objects['Destination']
track.object = obj['dest']                          # Set the object to track to

#rayhit = obj.rayCast(obj['dest'].worldPosition, None, 30, '', 1, 1)    # Shoot towards the destination object

rayhit = obj.rayCast(obj.worldPosition + obj.localOrientation[1], None, 30, 'laserhit', 1, 1)

print (obj.localOrientation[1])

if rayhit[0] != None:

    dist = obj.getDistanceTo(rayhit[1])               # Get the distance to the destination object's edge
    obj.scaling = [1.0, dist, 1.0]                      # Scale in the Y direction toward the destination object
    #cont.activate(track)                                # Rotate toward the destination object; not necessary for just a forward shot
    obj.scaling = [1, 30, 1]

This is important piece of diggable terrain openworld.I am going have to store the finale scale in python.

I do not know why you clutter your code with these cryptic abbreviations. It makes your code really hard to read. I’m sure your computer can handle words with more than 4 letters ;).

from bge import logic
import mathutils

Y_VECTOR = mathutils.Vector([0,1,0])

controller = logic.getCurrentController()
owner = controller.owner

positionBehindOwner = owner.worldTransform * Y_VECTOR
maxMeasureDistance = 30

hitObject, hitPosition, hitNormal = owner.rayCast(
    'laserhit', 1, 1)

length = maxMeasureDistance

if hitPosition:
    vectorToHitPosition = hitPosition - owner.worldPosition
    length = vectorToHitPosition.length

owner.localScale.y = length

This code isn’t much different to what you already have. It should scale the controller’s owner along y. The difference is how to calculate the target position (positionBehindOwner).

I suggest to rename the property “laserhit” to “hitable” or “laserhitable”. This indicates it is a flag rather than a value, or a result.

Be aware:

  • the ray will not stop at objectToTrack. It will stop at the first hit latest at 30BU.
  • the controller’s owner will not turn (unless you activate trackTo).
  • the measure will not measure towards the tracked object - it measures along the local +Y vector

This is not my code.It is solarlune’s code.He’s been on this forum before but not very much.