Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Mupp on February 27, 2018, 08:44:05 PM

Title: Raycast and collider questions
Post by: Mupp on February 27, 2018, 08:44:05 PM
Hi, there are some things I can't figure out about raycasts and colliders so I have to ask here.

First, is it possible to change the origin point of a raycast? I've tried the "from position" values but they do nothing. I've also noticed if you offset the collider on the object the origin point seems to offset itself in the opposite direction.

Second, is there a way to detect which collider you hit if the object has more than one? Also, is there a way to check which side of the collider is hit?
Title: Re: Raycast and collider questions
Post by: jeanfabre on February 28, 2018, 12:59:21 AM
Hi,

 'from position' is an override and if you have defined a gameobject as the point, it may be ignored. Can you tell me exactly what action you are using?

let me know which action you are using, I'll check, I think you can, but maybe it's not exposed, you get only the GameObject hit, not the collider component, but then, what woudl you make up of that? if you have a good use case, I[ll consider making some custom action for this.

checking collider side is something Unity doesn't provide, so you'll have to implement this feature yourself. Typically, I would not bother and try to have children with each a collider acting as a side, or if it's too much, you use the hit point and do some vector math with the hit object transform, where you can then deduce the side. It's fairly complex vector math, though so make sure you read about this online first.

Bye,

 Jean
Title: Re: Raycast and collider questions
Post by: Mupp on February 28, 2018, 11:03:31 AM
Hi,

 'from position' is an override and if you have defined a gameobject as the point, it may be ignored. Can you tell me exactly what action you are using?
I've tried both with and without a defined game object but it doesn't seem to do anything. I'm using regular 3d raycast.
Quote
let me know which action you are using, I'll check, I think you can, but maybe it's not exposed, you get only the GameObject hit, not the collider component, but then, what woudl you make up of that? if you have a good use case, I[ll consider making some custom action for this.
Ok, this is what I try to do. The physics engine is so bad that I feel I have to fight it for every simple thing I try to do. I'm making a "2d platformer" in 3d space and right now I have 2 problems.

First is ground detection. If I can only fire a raycast from the center straight down the game will think I'm in the air if you move just a bit off of a platform even if you actually are mostly standing on it. I'm using this with a combination of "on collision exit" but that causes problems if I hit a platform with the head for example. That's why I wondered if you can check which collider you hit and where.
I also want to fire a ray at the feet to check the hight of a step, cause I don't want to use a angled collider at the feet because that would practically make  all platforms have sloped edges.

Second problem, I get stuck when jumping at the side of a platform. The answer to this is said to use a physics material with no friction but I can't get that to work at all. That's why I want to check where the collider is hit so I can manually set the force to 0 when the player hit his side to the side of a platform.
Quote

checking collider side is something Unity doesn't provide, so you'll have to implement this feature yourself. Typically, I would not bother and try to have children with each a collider acting as a side, or if it's too much, you use the hit point and do some vector math with the hit object transform, where you can then deduce the side. It's fairly complex vector math, though so make sure you read about this online first.

Bye,

 Jean
I've thought about that, but can you fire a ray from a child object without having to use global variables?

Thanks.
Title: Re: Raycast and collider questions
Post by: Doh on February 28, 2018, 06:34:33 PM
You can use a child as the "from Game Object" parameter, this works quite nicely if you are prototyping and need to iterate visually.