Can anyone point me to a few raycasting examples, but not the BGE api documentation…I have been going over that for about 2 hours:p. I just need simple working barebones examples. I am trying to find the vector to a ray hit and place my character there(position.z) for my first movement script, but mine does not seem to be working
hitobj, hitpoint, hitnormal = player.rayCast(ground_target, player_vec, 20, '', 1, 0, poly, 0)
player.position.z = hitpoint.z - 3
I did predefine the to and from vectors, but I am not sure I am understanding the documentation 100%
either that or assigning the z value to the character is just wrong?? Or using the character physics object is? I want to prevent the player from sliding around on slopes atm.
EDIT: managed to work out a solution after some help in this thread(and a little bit of proofing, since people like to give false code to get people to do some work on their own ;))
player_vec = ([player.worldPosition.x, player.worldPosition.y, player.worldPosition.z - .5])
ground_target = ([player.worldPosition.x,player.worldPosition.y,player.worldPosition.z - 20])
ray = player.rayCast(ground_target, player_vec, 2, '', 0, 0, 0)
bge.render.drawLine(player_vec,ray[1],(1,1,0))#debug visual aid
if ray[1]:
tempVec = ray[1]
player.worldPosition.z = tempVec.z + 1.2
if forward == pressed:
player.applyMovement((0.2,0,0), True)
if back == pressed:
player.applyMovement((-0.15,0,0), True)
if left == pressed:
player.applyRotation((0,0,.05), True)
if right == pressed:
player.applyRotation((0,0,-.05), True)