Click on object starts player movment

iop 5 months ago in Game Creator updated by Marti (Lead Developer) 5 months ago 5


I have a player character and a second character in my example scene. The player uses the "point and click" input type. There is also a cube with a trigger. When u click the trigger, it starts actions which move the second character to the cube. This is all fine. But when i click the cube my player also starts running to the position of the cube which he shouldnt. I think this happens cause the raycast hits the plane underneath and the players starts running there. I want to prevent the player from running to the cube when clicking the cube. I tried the "mouse layer mask" which doesnt work cause it still hits the plane. I also used the "change property" "is controllable" in the actions. This works but is not a realy good solution cause I would have to use this on every clickable object and the player still moves a little bit then. Is there a known solution for my problem?

Unity version:
Game Creator version:
Satisfaction mark by iop 5 months ago

There is no "automatic" solution for this problem. Most point & click games have a button dedicated to inspecting things (like right clicking) and another one for moving the character.

I was going to suggest using the "is Controllable" property to control when the character can or cannot move, but I see you've already explored this option.

The thing is that the Point & Click makes the best effort to find a position to move. For example, clicking outside the navigation mesh will make the player move to the closest point.

Thx for your answer!
Do you use some kind of raycast if you click somewhere on the terrain? If yes you would get all objects hit by the raycast. Would it be possible just to just stop the navigation if the first object you hit is not on a specific layer? 
Can you give me a tip where to start if want to try to change the code to achieve such a behavior? 

The problem with that solution is that you don't have any control over whether the click will call the move character point & click system or the object's Trigger. So the best solution in this case would be setting the Player's Is Controllable to false and activate it at the end.

I tried the following and it solved the probelm described above for me:

I created this Actions:

and this test script:

I also tried the action on the player character and it worked, too (when i set the mouse button to "rigth mouse button click" which u cant use on mobile anyway)

Do you see any problems with this approach? Is there a even more simple solution where I can use the "moveTo" function of the character directly?


Yup! That should perfectly work. However, as you mention, you could even tell the character to move to that position directly through the code, without having to call another Actions object to make the "Move Character To" Action. The line of code to do that is the following:

//myCharacter is a Character type variable
// position is a Vector3 of the position to move to
// rotation is a ILocomotionSystem.TargetRotation instance. Set it to null if you don't want the character to move to a certain position.
// stopThreshold is a float that's the amount of error you can have when reaching the destination. It's usually a good practice to set it to 0.01 or similar.
myCharacter.characterLocomotion.SetTarget(position, rotation, stopThresh);

However, this will make the character start moving towards its destination, but won't wait until it reaches it. If you want to hold the Action until the character arrives, check out the ActionCharacterMoveTo.cs script from the Game Creator package. The Execute() method shows how to do that.