playMaker

Author Topic: Problem with Get / Set Position Triggers  (Read 2536 times)

Matthew Reilly

  • Playmaker Newbie
  • *
  • Posts: 20
Problem with Get / Set Position Triggers
« on: April 19, 2019, 12:19:40 PM »
Hi All,

I've set up a number of teleportation triggers in a game. Basically, the goal is to GET the game manager holding my 3rd-person player controller, animated player prefab, and camera, and to SET it 100 or 200 below in world space (where I've made a weird mirror world). Once all is wrapped up in each of these teleports, I'd like to shoot back to the original place I initiated the trigger (either 100 or 200 up on Y axis).
After the first one works, the later trigger areas either don't send me underground OR they send me down there & strand me there. This latter thing even happens when the XYZ on Player Manager is well above the ground in world space. Is there an easy fix for this situation? It seems I'm messing up the positioning on this player manager & that's why I either 1. don't teleport after trigger one or 2. I teleport down and get stuck. Thanks for any help! 

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Problem with Get / Set Position Triggers
« Reply #1 on: April 19, 2019, 12:43:29 PM »
Hi.

from what i understand, in some places you need to move 100 and other 200?
Maybe you could just set some empty game objects to the target position, and store as a value in the trigger, then move player to that position.

if that is not what you mean Can you show what you want to achieve in a video or some images?

Matthew Reilly

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Problem with Get / Set Position Triggers
« Reply #2 on: April 19, 2019, 02:14:22 PM »

I just made a quick demo vid.... the initial trigger gets pos of player manager game object, sets pos of player manager variable and executes a narrative block on fungus. Once fungus stuff is done, I activate a game object duplicate of building trigger... this gets player obj every frame & sets pos of a variable either 100 or 200 up on y axis in set pos vector three.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Problem with Get / Set Position Triggers
« Reply #3 on: April 20, 2019, 05:41:06 AM »
Hi,
Can you show the fsm/states/actions that you use to teleport and back.

Is the fsm on the trigger handling the set pos if so?

Are these triggers placed @ runtime or preset?

if preset, i would set 1 or 2 empty game objects that will be used to position the player (TargetPosLowerWorld and TargetPosUpperWorld.
So fsm on the trigger would go like this :
On trigger enter, set player position to 'TargetPosLowerWorld' then when fungus story telling is done, set player to 'TargetPosUpperWorld'

if not preset i would the something similar, but use 1or2 raycast downward one for upper world and 1 for lowerworld, this could prevent player get stuck inside a world.
The raycast hitpoint can then be used to position the player. (with a Y offset if needed)

Matthew Reilly

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Problem with Get / Set Position Triggers
« Reply #4 on: April 22, 2019, 12:27:23 AM »
Thanks for this reply djaydino. I'm new to Unity and my limited knowledge is that presets are useful ways to apply / duplicate settings without manually typing in too much? In any event, I didn't use them here & I'm not sure how you would initiate (activate? instantiate?) a game object preset once/only when the player enters a trigger. I looked into Global Variables, but for some reason my player / target areas (in the version I tried with your recommended setup A) aren't showing up as an option in the Global Variables... (I've also tried tweening and Vector XYZ set/get in other practice iterations, so this trigger teleport has been a bit of a pain)... As far as raycasting, I'm pretty clueless there. I've watched your youtube video & tried to apply to my game. No such luck in my particular case. This raycasting tutorial seems very useful, however. Thanks!

I'm probably doing something problematic inside the FSMs currently in the game?--->

Unity Game Object #1: B_1 (Building 1 trigger sends up to the higher of the two underground areas)

PM BLOCK ONE:
*Trigger Event*
Use Owner
OnTriggerEnter
TagPlayer
Send Event B_1 Trigger (Ideally the story will change radically based on these decision points, so I'd like to register where player has been & to add an Int Var later in the making of this game...
Store Collider PLAYERMANAGER (a variable for a mostly empty parent game object with the player and camera as children).

TRANSITION--B_1Triggered

PM BLOCK TWO:
*Get Position PLAYERMANAGER (GAME OBJECT)
None x 4
World Space
Every Frame

*Set Position PLAYERMANAGER (VARIABLE)
Vector None
X None
Y 100
Z None
World Space
Every Frame

*Playmaker Execute Block
(Fungus) Block Name B_1 / Flowchart
Not every frame
 
Unity Game Object 2 (INACTIVE ON GAME START): B_1Return
Once activated, this object teleports player from one of the two underground areas back to the 3-d above-ground area... I use Fungus script to de-activate B_1 and to activate B_1Return (& all other similarly-made FSMobjects). I haven't decided whether to return the player to the original spot of B_1 or to shoot the player up through ground at the XZ corresponding to their underground position. Probably the latter...). Anyways... getting ahead of myself. B_1Return goes like this:

* Get Position PLAYERMANAGER (GAME OBJECT)
None x 4
World Space
Every frame

* Set Position PLAYERMANAGER (VARIABLE)
Vector None
X None
Y 1000
Z 0
Self Space
Every Frame

So, after two buildings/ triggers have been set off (B_1, B_1Return, B_2, and B_2Return) the player either won't zoom underground or won't resurface, making this game element pretty much useless (* or worse *). I think you are right that the player is getting stuck in terrain. If it helps any, there are two blended terrain objects—both of them have custom sprite textures (from a cell phone picture of my wife's 2-d pastel cartoons). Ok, hope this clarifies some & thanks djaydino & anyone else who has recommendations here. 

There are 40 of these buildings, so perhaps presets would be the better way to go? These buildings are the way I'm communicating the overarching narrative / but they are also an entry into 2 large open underground areas (below main level) where the sound is consistent with above ground... this way they can be used for navigation to get around difficult areas above ground (a la "Marco Polo"-style game).

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Problem with Get / Set Position Triggers
« Reply #5 on: April 22, 2019, 10:43:06 AM »
Hi

Quote
I haven't decided whether to return the player to the original spot of B_1 or to shoot the player up through ground at the XZ corresponding to their underground position

there is a big difference to set this up.
and placing the player up on current position is probably easier that the 1st option.

For this you could use a raycast above the player and above the 'above ground' terrain.
Give the 'above ground' a separate layer. (to use in the raycast)

Do raycast downward and set layer only to 'above ground' layer.
Set a large distance to be sure to always hit the surface of the 'above ground'

Store the hit point and use that to set the position of the player.

if you want to know if triggers have been used, you can use a bool on the triggers that you can set to true once it is used.

But if you want to save it so that when player plays the next time (after quitting the game) then it is better to use Array Maker arrays together with Easy save (asset)

Which raycast tutorial did you watch?

Matthew Reilly

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Problem with Get / Set Position Triggers
« Reply #6 on: April 22, 2019, 01:09:28 PM »
Hi again.

I'm not sure I follow this process...
two quick clarification questions:
* So, should there be two raycasters? One above ground and one above the player?
* Do I child the raycaster or smooth follow the player or something to keep it in the right place in the level?
* Is the raycast an action coming from the player or is it a totally separate game object?
* Do I set the raycaster to self or world space?
* Would you recommend any tutorials on this form of raycasting?

My current attempts at setup either shoot the player horizontally off of the level and into the abyss (where they don't fall but just kind of float) OR it sends them through the ground & falling downward. Sorry for the difficulty here... I'm new to raycasts!


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Problem with Get / Set Position Triggers
« Reply #7 on: April 23, 2019, 03:09:05 AM »
Hi.
In this tutorial i use raycast to place bullet hole images.


Think of it as a laser, it will shoot a line from a chosen position into a chosen direction.
When it hit something, you can store the object/distance/position etc.

With layers you can select which object types can be hit and which the line should ignore (pass thru)

So in your case you can get a position above the player and raycast downward (i believe it is y -1)
and you can set Space to 'World'

To get the correct position to cast from, you could set a empty child object (like the weapon tip in the video)

or get the players current (world) position and on the result use "Set Vector3 XYZ" and set the Y position to a y position above the 'above ground' terrain.

Then use that on the raycast 'From Position' and leave 'From Game Object' empty

You should also set the distance large enough to always hit the terrain.