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

Author Topic: [Resolved] Raycast3D Usage  (Read 4657 times)

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
[Resolved] Raycast3D Usage
« on: Jul 04, 12, 08:25:05 PM »

I'm attempting to use Raycast3D to get targets infront of my camera but I am running into various issues which I am sure are related to not know how it and camera data are used.

For example, the returned camera position of a camera does not seem to include its offests, resulting in the ray not fireing from the camera but the point at which it is attached to the character.  Okay, so for now I get around that by using the FP camera, however, the rays are not shooting in the direction the camera is pointing even those the direction sent is gotten from getcamerarotation.

In the FPS demo, I see in various methods that have adjustments going on for the camera rotation, but I'm missing something on when and why this is being done and simply dropping that code in doesn't result in any better ray direction.

I guess I expected to pass the camera position and its direction and simply get a ray that shot directly from the camera.  However, this is not what shows using:

Code: [Select]
  hit_node = Raycast3D( start_pos, adjusted_rotation, excluded_nodes, distance, intercept, mesh_name )
 
  DrawDebugLineSegment(start_pos, start_pos + (direction * distance), "FF0000", 1.0, false)
  if intercept != (0,0,0)
    DrawDebugPoint(intercept, 0.05, "00FF00", 1.0, true)
  .

The rays shoot in some sort of offset from the actual camera direction resulting in hits from behind or the side depending on current direction.

Is there anyplace I can get documentation beyond the command descriptions in the wiki?  Or can anyone point me to what I might be missing here?
« Last Edit: Jan 03, 13, 10:22:40 AM by HE-Cooper »
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Raycast3D Usage
« Reply #1 on: Jul 04, 12, 11:21:36 PM »

This seems to work for me
Code: [Select]
method debugDrawCone(nodeToTest as NodeRef of Class HBNode)
  theTimer as NodeRef of Class genericTimer = CreateNodeFromClass("genericTimer")
  thetimer.timerData = nodeToTest
  thetimer.myTimer.script = SYSTEM.EXEC.THISSCRIPT
  theTimer.myTimer.fireRate = 00:00:01.000
  thetimer.myTimer.start()
.
function myTimer_tick()
  timer as NodeRef of Class genericTimer = me

  if $BASECLIENT._GetAreaName() <> "Character Selection" //Quick way to just stop the script if we go to the character selection area
    numLines as Integer = 5
    nodeToTest as NodeRef of Class HBNode = timer.timerData
    cam as NodeRef = GetActiveCamera()
   
 
    distanceFactor as Float = 20
    loop i from 0 to numLines
   
   
      sourcePosVec as Vector3
      sourceRotVec as Vector3
 
      headingVec as Vector3
 
      targetingRay as Vector3
      var angleAround = (i * numLines) / numLines * 4
 
   
      //Get our source node position and rotation
      GetNodePosition(cam,sourcePosVec)
      sourceRotVec = GetNodeRotation(cam)
      sourceRotVec.y = sourceRotVec.y - angleAround + 10
   
   
      headingVec.x = sine(sourceRotVec.y)
      headingVec.z = -cosine(sourceRotVec.y)
      headingVec.y = -sine(sourceRotVec.x)
   
      headingVec *=  distanceFactor
 
      targetingRay = (headingVec)
     
 
      collideIntercept as Vector3
      meshName as String
      exclude_nodes as List of NodeRef
      add back nodeToTest to exclude_nodes
 
      var character  = Raycast3D(sourcePosVec,targetingRay,exclude_nodes,distanceFactor,collideIntercept,meshName)
      if character <> None
        where character
          is kindof _NonPlayerCharacter
         
            $Debug._drawDebugRay(sourcePosVec, collideIntercept, 0.02, "00FF00", "00FF00", 0.3, false)
            sendchat("Your Character sees "+ character.GetMyName(),"GAME")
          .
          is kindof HBNode
            $Debug._drawDebugRay(sourcePosVec, collideIntercept, 0.02, "00FF00", "00FF00", 0.3, false)

          .
          default
            $Debug._drawDebugRay(sourcePosVec, collideIntercept, 0.02, "00FF00", "00FF00", 0.3, false)
          .
        .
      else
      .
    .
  else
    timer.myTimer.stop()
    me.Stop_Selection()
  .
.
method Stop_Selection()
  DestroyNode(me)
.
For me to test this, I just  use the following in "E_CharacterSystemClassMethods"

Code: [Select]
method HE_OnSetControlledCharacter( char as NodeRef of Class HBNode ) as Boolean
  // this was script erroring Cwiss, I am guessing you are still in the middle of this
ss as NodeRef of Class SelectionSystem = CreateNodeFromClass("SelectionSystem")
ss.debugDrawCone(char)
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: Raycast3D Usage
« Reply #2 on: Jul 04, 12, 11:43:42 PM »

Thank Jrome, I'll check this out.  thanks again.
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: Raycast3D Usage
« Reply #3 on: Jul 05, 12, 01:28:18 AM »

Thanks a lot.  That code provided much more predictable behavior.  It is still shooting from the characternode rather than the camera itself in over the shoulder but is otherwise acting as expected.

I was further able to address this with the following:

Code: [Select]
      //Get our source node position and rotation
      //GetNodePosition(cam,sourcePosVec)
      sourcePosVec = GetCameraPosition(cam["CameraName"])

This addressed camera position not taking offset into account.

and

Code: [Select]
myPlayer as NodeRef = GetPlayerCharacterNode()
    ACCController as NodeRef of Class _ACCController
    ro as Vector3
    where myPlayer
      is kindof _ACCControllerOwner
       
        ACCController = myPlayer._getACCController()

        if ACCController <> None
          ro = ACCController._getGameCameraRotationalOffset()
        .
      .
    .



      sourceRotVec = GetNodeRotation(cam)
    //  println("rot offset - " + ro.y)
      sourceRotVec.y = sourceRotVec.y - ro.y
      sourceRotVec.y = sourceRotVec.y - angleAround + 5



This applied my camera rotational offsets on the over the shoulder cameras so they weren't shooting off to the left or right.
« Last Edit: Jul 05, 12, 02:00:07 AM by DragonFist »
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Raycast3D Usage
« Reply #4 on: Jul 05, 12, 01:56:34 AM »

Thanks a lot.  That code provided much more predictable behavior.  It is still shooting from the characternode rather than the camera itself in over the shoulder but is otherwise acting as expected.

I am currently still using the default camera. Have yet to try anything else.
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: Raycast3D Usage
« Reply #5 on: Jul 05, 12, 02:06:50 AM »

No worries, sorted it all out.  Put the changes I made to work with other cameras in an edit of the last post.
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Raycast3D Usage
« Reply #6 on: Jul 05, 12, 02:16:08 AM »

No worries, sorted it all out.  Put the changes I made to work with other cameras in an edit of the last post.

Good to know.
 :)
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: Raycast3D Usage
« Reply #7 on: Jul 05, 12, 02:39:39 PM »

The raycasting in use:

http://youtu.be/D_6VUk6A6bM

I am currently doing this on the mousemove event but am likely to create a targeting system class with a timer to the major of the handling (though I might still keep/add the selection to mouse move and movement keys as well as "do action" kind of stuff for between tick handling and to attempt to keep selection as up to date as possible.  I'm open to any theory crafting others might have on this.
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Raycast3D Usage
« Reply #8 on: Jul 05, 12, 02:58:56 PM »

The raycasting in use:

http://youtu.be/D_6VUk6A6bM

I am currently doing this on the mousemove event but am likely to create a targeting system class with a timer to the major of the handling (though I might still keep/add the selection to mouse move and movement keys as well as "do action" kind of stuff for between tick handling and to attempt to keep selection as up to date as possible.  I'm open to any theory crafting others might have on this.

looking good

How many rays are you casting?
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: Raycast3D Usage
« Reply #9 on: Jul 05, 12, 03:11:45 PM »

I'm using the 5 in your code at the moment.  I intend to review that, perhaps do more than just the y axis, and tighten it up a bit more as I plan to have mesh part specific targeting in some instances.  But that is for later.

Mostly, the plan now is to get it into a targeting system that distinguishes friendly targets and interactive objects from opponents, etc. while passing the mesh name in for later use.

Then I'm going to start working on the actual abilities, skills, etc. to apply to targets.  I.e. attacking things, healing, etc. which I plan to do via reverse replication after client side predication of the results with server side processing and correction.
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Raycast3D Usage
« Reply #10 on: Jul 05, 12, 03:16:22 PM »

What happens if you have multiple targets getting hit at once? Are you only selecting the one that is closest to the center raycast?
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: Raycast3D Usage
« Reply #11 on: Jul 05, 12, 03:34:56 PM »

My intention is to use the first hit, which will usually be on the first raycast with no adjustment, with a few in a cone around it at a tight angle just for some breathing room.

All I'm doing with this and making the selection which will be visible to the player and use that data (I also plan to have it be able to remove selection when nothing selectable is in the raycast.

Server side will do a check for the time of the action with a much broader cone just to ensure the client's data was reasonable at the time of the attack to prevent packet editing programs from telling the server "I made a successful melee attack from the other side of the zone with 5 trees and a rock between me and the target."   As long as the target was reasonably close to weapon range and character direction, we'll assume it is okay to calculate hit and damage based on an RPG ruleset.
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: Raycast3D Usage
« Reply #12 on: Jul 07, 12, 02:07:59 AM »

More recent video after putting the code on a timer and adding a check for the target being closer than the camera offset to prevent targeting mobs behind the character (which adds the mob too close to the excluded list and tries again).  Also, if there has been no selection for 1 sec, we drop the target.

I plan to give the player a target lock, but other-wise this is the targeting method - no tab targeting.

http://youtu.be/qewo8ziZ6ZU

Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: Raycast3D Usage
« Reply #13 on: Jul 09, 12, 06:05:04 PM »

Okay, this is generally working as expected.  However, every so often, I get rays shot at random angles.  I at first thought it only occurred while moving but that is not the case.  Occasionally, this is accompanied by an error in the console about an invalid ray direction or fxnode.  The result is that one gets random mobs selected that are off-screen, sometimes directly behind the camera, that a moment later revert to the expected selection.

I'm toying with the idea of using one of the other selection methods like nodes in cone or something to verify the validity of the ray, though that seems to be a potential over use of resources that may have performance complications (the reason I don't simply use one of those is that I wish to use the "mesh name" feature to allow attacks to specific body parts).

Any ideas on how to address these errant rays?
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Raycast3D Usage
« Reply #14 on: Jul 09, 12, 06:16:55 PM »


I'm toying with the idea of using one of the other selection methods like nodes in cone


Are you referring to this: http://hewiki.heroengine.com/wiki/Technical:Area_Awareness
Logged
Pages: [1] 2