Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  3. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

anti-Slenderman teleporting

Discussion in 'Scripting' started by thunderdawn, Dec 6, 2018 at 3:38 AM.

  1. thunderdawn

    thunderdawn

    Joined:
    Sep 30, 2017
    Posts:
    26
    Hi! I’d be grateful if you could offer me some advice.

    I have a feeling it’s a very basic thing but I come from the art side so programming is mind-bending sometimes.

    I have several non-animated objects in a 3D scene with a terrain. These objects need to change locations semi-randomly once every few minutes. There is a list of locations but the choice between them is random.

    Of course they also need to check collision so two or more of them won’t choose the same location at the same time but that’s fine.

    The problem is, they are fairly large so the player (first person camera) will notice. I need the player to either look away or be far away from them at the moment of teleportation. But the player can’t be far away from all of them, because their locations are distributed through the whole scene. So the condition needs to be: far away from the object that’s teleporting at the given moment while also far away from the new location of said object.

    How do I do it? Every tutorial I find is about objects following the player or randomly teleporting to the player.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    2,877
    One approach might be to allocate a bunch of specially-named objects and identify them (tags, special scripts, their name, etc), and these will be there "where can you move an object to?" locations.

    Then at runtime when you decide to move object X, you will check:

    - is object X too close that the player would notice it moving?
    - choose a random destination game object:
    --> is that too close the player might notice?
    --> is that too close to another object?

    If all those conditions are satisfactory, move the object.

    Vector3.Distance() can be used to determine distance.

    Casting X distance in front of the player and then testing for objects being within radius X of that forward-cast spot is one handy way to check "is in front of me."
     
    thunderdawn likes this.
  3. thunderdawn

    thunderdawn

    Joined:
    Sep 30, 2017
    Posts:
    26
    Thank you, I'll try it.
     
  4. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,399
    Just as another option (I have no idea if this is better or worse- it is simply different) you could try something like this :-
    1. Create a cube the size of the teleporting object. Make it completely transparent.
    2. Add to it a script that monitors its visibility; see OnBecameInvisible (I am hoping that the fact it is transparent won't affect this).
    3. Place them at all the spawn sites.
    4. Now you can teleport from a spawn point that (a) has a thing to be teleported (b) is invisible and (c) there is another site that has no slender-man and is also invisible.
     
    thunderdawn likes this.
  5. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    681
    Why must the player be far away?
    can't it be enough that he simply isn't looking that way?

    if so you can check the direction to the object, compare the dot product of transform.forward and that direction and only allow to teleport to spots that are also negative on the dot relative to the player.
     
    thunderdawn likes this.
  6. thunderdawn

    thunderdawn

    Joined:
    Sep 30, 2017
    Posts:
    26
    Thanks!
    The transparent thing seems to mess it up when I try to switch back but I think that might be me.
    Mm I thought it would be easier to provide some distance. But gameplay-wise it's enough if they don't look. I only want to create the impression of items magically moving around.