Hello,
What I am trying to do currently is get the position relative to a model, and then use that to make a bullet ray query. I understand how to get the position of the model itself, but I would also like to get the position 100 units in front of it. If not, is there a standard way of getting these positions? I’ve tried making my own, but I think it is not working correctly (and seems overcomplicated for something like this). Thanks for the help!
What I have right now:
Functions from conversions module:
from math import cos, sin, sqrt, pi
# getting x and y coords for a point with length from (0, 0) and total angle of the object's angle,
# plus the angle of the ray relative to the object
# (0, 45, 10 gives a ray 45 degrees to the left of an object looking in the y direction)
def getBeamPosition(objectangle, rayangle, length):
totalangle = objectangle + rayangle
totalangle = convAngle(totalangle)
totalangle = math.radians(totalangle)
horizontal = length * cos(totalangle)
vertical = length * sin(totalangle)
return [horizontal, vertical]
# converts the angle from Panda's system to a 0-360 degree measure, working anticlockwise
def convAngle(angle):
if angle >= 0:
angle = 360 - angle
else:
angle *= -1
return angle
def Pythag(a, b):
return sqrt(a**2 + b**2)
In main script:
rayPositions = []
rayResults = []
# chassisNP is a BulletRigidBodyNode in the shape of a cuboid to act as the hitbox for the car body
carLoc = self.test_car.chassisNP.getPos(render)
carRot = self.test_car.chassisNP.getHpr(render)
print(carLoc)
## This is the intended setup, with 8 rays going around the chassis to determine how far away it is from a wall in these directions
# for i in range(0, 360, 45):
# beamLengthStartComponents = conversions.getBeamPosition(carRot[0], i, self.test_car.angleRadius[i])
# beamStart = carLoc + Point3(beamLengthStartComponents[0], beamLengthStartComponents[1], 0.2)
#
# beamLengthEndComponents = conversions.getBeamPosition(carRot[0], i, 1000)
# beamEnd = carLoc + Point3(beamLengthEndComponents[0], beamLengthEndComponents[1], 0.2)
# rayPositions.append([beamStart, beamEnd])
beamLengthStartComponents = conversions.getBeamPosition(carRot[0], 0, self.test_car.angleRadius[0])
beamStart = carLoc + Point3(beamLengthStartComponents[0], beamLengthStartComponents[1], 0.2)
beamLengthEndComponents = conversions.getBeamPosition(carRot[0], 0, 1000)
beamEnd = carLoc + Point3(beamLengthEndComponents[0], beamLengthEndComponents[1], 0.2)
rayPositions.append([beamStart, beamEnd])
for count, i in enumerate(rayPositions):
rayResults.append(self.world.rayTestClosest(i[0], i[1]))
print(rayResults[count].getHitPos())
distanceVector = rayResults[count].getHitPos() - carLoc
print(conversions.Pythag(distanceVector[0], distanceVector[1]))
# Purely to seperate the prints from one frame to the next
print("------")