HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.
Pages: 1 2 [3]

Author Topic: which side of an object am I looking at?  (Read 6306 times)

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: which side of an object am I looking at?
« Reply #30 on: Mar 08, 15, 12:42:21 PM »

I really have no idea why was i so histerical about this problem, since the solution is not that complex.
With the huge help of Jrome i came to conslusion that there is a good chance something like this will work:

Quote
sourceNode as NodeRef = getaccountid()
  sourceNodeRot as Vector3 = sourceNode["Rotation"]

  characterForward as Vector3 = RotateVector( (1,0,0), sourceNodeRot )
  characterUp as Vector3 = RotateVector( (0,1,0), sourceNodeRot )
  characterSide as Vector3 = RotateVector( (0,0,1), sourceNodeRot )

  camera as NodeRef of Class CameraNode = GetActiveCamera()
  cameraRot as Vector3 = GetNodeRotation(camera)
  cameraDirection as Vector3 = RotateVector( (0,0,1), cameraRot )
  cameraDirection.z = -cameraDirection.z 

  dotForward as Float = DotProduct(cameraDirection, characterForward)
  if (dotForward > 0.5)
    println("back")
  else if (dotForward < -0.5)
    println("front")
  else
    dotUp as Float = DotProduct(cameraDirection, characterUp)
    if (dotUp > 0.5)
      println("bottom")
    else if (dotUp < -0.5)
      println("top")
    else
      dotSide as Float = DotProduct(cameraDirection, characterSide)
      if (dotSide > 0.5)
        println("left")
      else if (dotSide < -0.5)
        println("right")
      .
    .
  .


Also note two things:

-if you're using bones instead of character you might need to play with forward/up/side vectors:

Quote
  boneForward as Vector3 = RotateVector( (1,0,0), sourceBoneRot )
  boneUp as Vector3 = RotateVector( (0,0,-1), sourceBoneRot )
  boneSide as Vector3 = RotateVector( (0,1,0), sourceBoneRot )


- the directions flip depending on if you use the game camera or the fly camera

Logged
Pages: 1 2 [3]