Third Person Controller and Playmaker raycast problem

lubaszj

New member
Hello,
I am using Third Person Controller with Playmaker and I'm following a nice tutorial on Youtube. The tutorial calls for a "raycast" action using Playmaker. I have set a "look at" action for the "enemy" character to focus on the "player" character and that is working just fine. However when I try to add the raycast from enemy to player, the raycast debug line starts by aiming at the player, but it just sits stationary when I move the player character around. I can see that the enemy's forward position changes, the "look at" line follows the target, but the raycast never moves. This doesn't make sense as both the "look at" and "raycast" lines are coming from the same object. I don't understand why my raycast line won't follow the target. Is this some kind of issue between Playmaker and Third Person Controller or a look source script conflict? Please help.
 
Ok, so I solved the raycast line issue. The raycast from the enemy now follows the target player consistently. However, the issue has now become that the enemy character itself never faces the direction that the raycast is pointing. It just sits stationary. I have the raycast object as a child object to the enemy character. The "Z" position of both the parent and child objects are facing the same way. Shouldn't the child object turn with the parent object? Aren't they essentially the same object if one is a child to the other? If I set the raycast to come from the enemy character itself, the enemy will turn and face the target, but the raycast will sit in one position. If I set the raycast to come from the child object, the raycast will follow the target, but the character itself will sit stationary.
 
Last edited:
In Unity, any transform will move along with its parent, not the other way around. So in your case, your raycast object is following the player, but it's a child of the enemy object, so the enemy object won't be moved.

Unfortunately I'm not familiar with this particular use case of Playmaker, but I'm not sure why you'd need to use a separate raycasting object in this way - can this not be applied to the enemy object itself?

Also, there's a component called LocalLookSource which can be used to force characters to look at specific target transforms. For example, in the demo scene, the "Agent Nolan" gameobject has this component and has the Nolan transform set as its "Target" property, which makes the agent always look at Nolan. Maybe you could use this component instead?
 
In Unity, any transform will move along with its parent, not the other way around. So in your case, your raycast object is following the player, but it's a child of the enemy object, so the enemy object won't be moved.

Unfortunately I'm not familiar with this particular use case of Playmaker, but I'm not sure why you'd need to use a separate raycasting object in this way - can this not be applied to the enemy object itself?

Also, there's a component called LocalLookSource which can be used to force characters to look at specific target transforms. For example, in the demo scene, the "Agent Nolan" gameobject has this component and has the Nolan transform set as its "Target" property, which makes the agent always look at Nolan. Maybe you could use this component instead?
Thank you for the reply. I took your advice and applied the raycast to the enemy itself. This solved the issue. I was trying to stick to the tutorial instructions and that's why I was trying to do the raycast from a child object. Oh, well. I achieved the same objective with a bit of finagling, I spose. I wonder if the point of using separate objects was so that I could then later attach them to any parent object as pre-assembled AI components?
 
In Unity, any transform will move along with its parent, not the other way around. So in your case, your raycast object is following the player, but it's a child of the enemy object, so the enemy object won't be moved.

Unfortunately I'm not familiar with this particular use case of Playmaker, but I'm not sure why you'd need to use a separate raycasting object in this way - can this not be applied to the enemy object itself?

Also, there's a component called LocalLookSource which can be used to force characters to look at specific target transforms. For example, in the demo scene, the "Agent Nolan" gameobject has this component and has the Nolan transform set as its "Target" property, which makes the agent always look at Nolan. Maybe you could use this component instead?
Here's the issue that currently has me at a stand still..
I'm trying to configure three enemy AI behaviors to work in coordination and independently depending on the situation. I'm creating a "Line of Sight", a "Field of View", and a "Range of View." The "Line of Sight" is a Look At/Raycast action FSM. The "Field of View" is a check to see if the target falls between a 45 degree cone of view. And the "Range of View" is essentially a sphere collider around the "Enemy" that is a trigger to establish whether the target falls within it.
The tutorial I'm following has these 3 states as separate game objects, all basic cubes, as children to the same parent object, "Enemy With AI." I'm trying to use a prefab character as the "Enemy" and so I find I'm needing to adjust my approach a bit to follow along. I needed to attach the "Line of Sight" directly to the prefab because a child object can't control its parent. Sometimes I need to orient the "Enemy" to face the target in order for the scene to be believable, however when I force the prefab's "Line of Sight" to check if the target is within it using "Look At" and "Raycast" actions, the target is always in the "Field of View" as a result because the "Field of View" child object is oriented by the parent prefab. When the prefab turns to check for "Line of Sight", it becomes and endless state of both Line of Sight and Field of View as met conditions. The target is then never able to leave the "Field of View" because the "Line of Sight" is forcing it. I've been trying to hammer this thing together for 2 days.. basically 2 days straight. I'm noob, so.. I'm frustrated at this point.

What I want is for the Enemy to sit and wait for the target to enter is Range of View, then check to see if the target falls into the Field of View, and then if both of those states are met, to finally focus its Line of Sight raycast on the target. That's it.
 
Last edited:
It's tough to say what is going on since it sounds specific to that Playmaker tutorial, but if you're just getting started I recommend that you follow that tutorial without using UFPS. UFPS will only add another layer to things and will cause more confusion. Once you get it working as it does in the tutorial you can then apply it to a UFPS character.

The only thing that I can say is that the PlayMaker LookAt node will not work with a UFPS character since UFPS controls its transform. For this situation you can use the Rotate Towards task and have that task rotate towards a specific transform.
 
It's tough to say what is going on since it sounds specific to that Playmaker tutorial, but if you're just getting started I recommend that you follow that tutorial without using UFPS. UFPS will only add another layer to things and will cause more confusion. Once you get it working as it does in the tutorial you can then apply it to a UFPS character.

The only thing that I can say is that the PlayMaker LookAt node will not work with a UFPS character since UFPS controls its transform. For this situation you can use the Rotate Towards task and have that task rotate towards a specific transform.
Hey, thanks for that reply. That's very good advice. I'm going to take it. I'm walking away from this thing for a couple days to get some air, tho. I'm at that point where I'm realizing that this project is going to be like everything else I've ever tried to do without having any idea what I'm doing. I just had to jump in with my hammer and smash a few things first, haha. That's my style, guess. Now, that I can see what I don't know, I can get in line and start learning something. Have a good one. I'll be back.

EDIT: About that "Rotate Towards" task you're talking about.. Is that something I can access through Playmaker? Is it the "Quaternion Rotate Towards" action?
 
Last edited:
Yes, you can use the Start Ability Playmaker task to start the Rotate Towards ability. Rotate Towards is not a Playmaker node.
 
Top