playMaker

Author Topic: Help with Raycast  (Read 2233 times)

broesby

  • Playmaker Newbie
  • *
  • Posts: 14
Help with Raycast
« on: February 04, 2016, 02:06:28 AM »
Hi all,...

I am making a flyer that is supposed to hit some ground targets.

I want the flyer to have a kind of aiming gizmo appear on the ground where a raycast from the tip in the direction of flight hits the ground...

So far so good. I can set up the raycast without problems. I also succeed in testing for terrain hit with Raycast Hit info, then comparing a virtual terrain object with the actual terrain (except the Terrain trees alsa are counted as terrain but thats another matter)
Then I tried two approaches:

1) A gameobject (Sphere) is moved every frame to the Hit Point of the raycast.
2) A particle effect with short lifetime is moved the same way...

Works like a charm except for one thing...

When hitting the terrain the sphere or particles moves on the ground as expected...
But when the raycast no longer hits and is pointing up in the air the sphere/particles are for some reason stuck at the last point hit...

Tried all kinds of setups testing for "not hit" events.... but nothing works...

Plz help...

broesby

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Help with Raycast
« Reply #1 on: February 05, 2016, 09:24:03 AM »
Anyone? I'm really stuck here  :-[ :'(

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Help with Raycast
« Reply #2 on: February 05, 2016, 10:44:13 AM »
You can set the terrain layer as the mask of the raycast so it only hits things on that layer, this would ensure that it doesn't put the hit point anywhere but on the terrain.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: Help with Raycast
« Reply #3 on: February 05, 2016, 11:04:29 AM »
Ok this may be a long shot and I am a sleep deprived noob, but here goes my guess:

Could you store the hit point in a vector3, then get the Y axis into a global float and assumimg your craft only flies at a certain height- you could create the object when the hit points is below your craft's y or enable the object and disable it again?? So how i imagine it:

Empty object with a child sphere Object disabled, randomly on the ground:

State1: Float compare (when raycast y is below the height you need, send event)

State2: set object position to raycast point. get child (save to variable). Activate child. Finish state.

State3: move towards (or however you move your sphere now) and a float conpare (again waititng for the y to get too high). Finish.

State4: deactivate child sphere object. Finish and return to beginning???

Knowing my luck tonight, it wont work, but maybe it will give you a view from a simplistic noob mindset and help you see something you missed before lol. Ive only used raycasts once and then scrapped it and went running back to the simplicity of colliders lol, so Im clearly no expert... Good luck.

Edit: spellchecking  :)
« Last Edit: February 05, 2016, 11:07:13 AM by Zeldag »

broesby

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Help with Raycast
« Reply #4 on: February 07, 2016, 07:55:27 PM »
Hello both,... thx for your answers. I know about the raycast only hitting the terrain but it doesn't solve the problem  :-[ The sphere is still stuck at the last point hit, when the ray is no longer hitting anything. It works again as soon as the ray hits terrain somewhere again...

About the other solution, Zeldag, I follow you thoughts somewhat  ;) but I'm too tired and sleepdeprived as well right now to try it  :D I'll keep you posted if I can make it work... Cya,..