playMaker

Author Topic: Raycast Hit Normal... How?[SOLVED]  (Read 1756 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Raycast Hit Normal... How?[SOLVED]
« on: August 05, 2020, 11:38:44 AM »
Hiya,

Does anyone know how to use the Hit Normal variable in raycast2?

I've got my rapid fire lasers looking awesome, with little particle explosion (pooled) at the hit point on enemies. However, I'd like the particle explosions to 'stick' to the point on the enemy as it whizzes along.

At the moment, due to the high velocity of the enemies and player spaceship, the particles spawn at the hit point but are gone in the blink of an eye as they whizz offscreen.

I've looked into it, and found that Hit Normal is the thing to use, but I can't figure out how to use it.

As always, any help is greatly appreciated.

Thanks.
« Last Edit: August 07, 2020, 12:39:18 AM by curb47 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Raycast Hit Normal... How?
« Reply #1 on: August 05, 2020, 02:24:08 PM »
Hi.
Maybe This tutorial can help :


curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Raycast Hit Normal... How?
« Reply #2 on: August 05, 2020, 03:49:16 PM »
Thanks!

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Raycast Hit Normal... How?
« Reply #3 on: August 05, 2020, 04:00:24 PM »
Mmm.... That tutorial doesn't cover what I'm after. In the video he has bullet holes spawning on the hit point on the wall, which I've done (rather than bullet holes, I have little particle explosions). The wall is stationary.

What happens if the wall is moving? How do you get the bullet holes (Prefab Object with particle emitter in my case) to stick to the exact point on the mesh of the wall when it's moving?

Thanks.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Raycast Hit Normal... How?
« Reply #4 on: August 05, 2020, 04:34:33 PM »
Hi.
Instead of placing the bullet holes you could spawn the particle on the position instead and parent it to the object

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Raycast Hit Normal... How?
« Reply #5 on: August 05, 2020, 05:21:27 PM »
Oh? I didn't know you could spawn from a pool and tell the object to be a child of something else.

What's the action of that?

Thanks.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Raycast Hit Normal... How?
« Reply #6 on: August 05, 2020, 05:27:45 PM »

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Raycast Hit Normal... How?
« Reply #7 on: August 06, 2020, 05:24:56 AM »
Okay, the Set Parent action has worked to a degree... but I'm having my brain fried again.

It works like a charm on certain items, the little particle explosions (pooled prefabs) stay where the laser hit was, and when I pause the game and go to the Hierarchy I can see the spawned prefabs are indeed children of the hit object. Brilliant!

BUT...

For some reason, when I shoot certain objects (fast moving asteroids) the spawned prefabs DO become children of the hit asteroids, however, the particle emitter acts as though it's still referencing only the Hit Point, and moves off-screen and does not move with the asteroid, even though it's a child of it.

How come it works perfectly for some objects, and not others?

The only difference between the 'working' objects, and the 'not-working' objects, is that the 'not-working' objects have a rigid body component. But I don't see how that matters, as the particle prefab is still a child of it, and I have a couple of other objects that are also children and they move with the asteroid.

Any thoughts?

Thanks.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Raycast Hit Normal... How?
« Reply #8 on: August 06, 2020, 06:00:13 AM »
Hi.
Check The particle system settings.
Things like simulation space, or inherit velocity

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Raycast Hit Normal... How? [SOLVED]
« Reply #9 on: August 07, 2020, 12:38:59 AM »
Okay, I investigated the particle system, which was all correct, but in doing so I noticed the Prefabed object had a rigid body on it. I don't know why I put that on.

Any way, I removed the rigid body from the particle system prefab and now it all works just as intended!

Woop! woop! Onwards and upwards to the next problem!