#Collider

1 messages Β· Page 1 of 1 (latest)

severe flame
#

Can you show me the code?

#

@viscid raft
Opened a thread, so we have the stuff here, just fyi

viscid raft
#

Okie dokie thanks

severe flame
#

So that script is on the portal?

viscid raft
#

Yes

severe flame
#

And I'd need the code of it to help you, not sure why you reference the colliders

viscid raft
#

public class PortalTeleport : MonoBehaviour
{
    public GameObject objectCollider;
    public GameObject anotherCollider;

    private IEnumerator Teleportation()
    {
        SceneManager.LoadScene("Portal");
        yield return new WaitForSeconds(2);
        SceneManager.LoadScene("Level2");
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.transform.tag == "Player")
        {
            StartCoroutine(Teleportation());
        }    
    }

}

severe flame
#

Is the players gameobject's tag set to "Player"?

viscid raft
#

As in the portal?

severe flame
#

No

#

the player

viscid raft
#

Yes

#

it is

severe flame
#

Ok

viscid raft
severe flame
#

Can you screenshot both colliders on player and portal?

viscid raft
#

This is portal

severe flame
#

Ohhh

#

2d

#

OnTriggerEnter2D()

viscid raft
#

Still nothing

severe flame
#

And the other collider screenshot?

viscid raft
#

Player

severe flame
#

first one is portal, second one is player?

viscid raft
#

Yes

severe flame
#

Ok, can you show me the updated code?

viscid raft
#
public class PortalTeleport : MonoBehaviour
{
    public GameObject objectCollider;
    public GameObject anotherCollider;

    private IEnumerator Teleportation()
    {
        SceneManager.LoadScene("Portal");
        yield return new WaitForSeconds(2);
        SceneManager.LoadScene("Level2");
    }

    private void OnTriggerEnter2D(Collider other)
    {
        if (other.transform.tag == "Player")
        {
            StartCoroutine(Teleportation());
        }    
    }

}
severe flame
#

private void OnTriggerEnter2D(Collider other)
to
private void OnTriggerEnter2D(Collider2D other)

viscid raft
#

Okay so it loads my portal scene ... but doesnt load the next one

severe flame
#

I guess because you destroy the portal by loading the new scene

viscid raft
#

So should I add a void Start() on the portal scene to load next scene after 2 seconds?

severe flame
#

You can do DontDestroyOnLoad(gameObject); on the portal in the Start function, and then do Destroy(gameobject) after loading the second scene

#

This will prevent a scene load from destroying the portal

#

Might not be the most elegant solution but it should work

viscid raft
#

public class PortalTeleport : MonoBehaviour
{
    public GameObject objectCollider;
    public GameObject anotherCollider;

    private IEnumerator Teleportation()
    {
        SceneManager.LoadScene("Portal");
        yield return new WaitForSeconds(2);
        SceneManager.LoadScene("Level2");
        Destroy(gameObject);
    }

    private void OnTriggerEnter2D(Collider other)
    {
        if (other.transform.tag == "Player")
        {
            StartCoroutine(Teleportation());
        }    
    }

    private void Start()
    {
        DontDestroyOnLoad(gameObject);
    }
}
#

Like this?

severe flame
#

Yes

#

But your solution is also a nice idea, having a script run in the Portal scene to switch scenes again

#

What you can also do if it gets more complex than this (Having lots of worlds with lots of teleports), have a "Teleport Manager"

Basically an empty gameobject with a script on it that is set to "DontDestroyOnLoad", whenever you want to teleport you just tell that script to trigger the teleport

#

Sorry if thats a bit complicated, just want to nudge you into the right direction from the start πŸ˜„

viscid raft
#

Makes sense, thanks!

severe flame
#

If you should follow that in the future your next problem will be finding that script from anywhere, you have two solutions (Prefacing this, because it WILL be a problem then):

  • Singleton on the teleport manager
  • GameObject.Find("NAME")
viscid raft
#

Ah this works perfectly. Now to find a good teleportation animation - the rick and morty one looks so out of place haha

severe flame
#

Yeah thats up to you now, I am terrible when it comes to the creative part πŸ˜„

viscid raft
#

This is what ive got so far - the animation looks so out of palace XD

severe flame
#

Though i suggest looking at the free assets in the asset store, some gems in there sometimes

#

Wow, that looks way better than anything I had in my earlier gamedev stages πŸ˜„

#

Just a suggestion, if you want to show a video, dont load a new scene for it, use UI that is hidden, and show it once you trigger a teleport, then switch scenes

#

Scene switches should be as low as possible, that will just set you up for problems πŸ˜„

viscid raft
#

Do you know of a bug that would cause my space bar to jump to only work like 1 fifth of the time @severe flame ??

severe flame
#

Can you Show me the Code of it?

viscid raft
#

There @severe flame

severe flame
#

Where does the grounded come from? Check if its correctly Set whenever you want to jump

viscid raft
#

Im honestly not sure, I found the script on unity

severe flame
#

Then output the grounded variable whenever you press the spacebar and check it with that

viscid raft
#

So use a Debug.Log and print the grounded when space is pressed?

severe flame
#

yes

viscid raft
#

That could be the issue

#

It outputs

#

"False"

#

and then gives me an error saying that the parameter grounded does not exist

#

and velocityX does not exist

#

@severe flame ```cs

public class PlayerPlatformerController : PhysicsObject
{

public float moveSpeed;
public float jumpHeight;
Rigidbody2D rb;

void Start()
{
    rb = GetComponent<Rigidbody2D>();
}

void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
    }

    if (Input.GetKey(KeyCode.D))
    {
        rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
    }

    if (Input.GetKey(KeyCode.A))
    {
        rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
    }
}

}

#

Works perfectly apart from when you jump, it doesnt STOP jumping

#

And doesnt stop walking either

#

I made one change to the code to make it so it does actually stop walking when you release

#

but it still doesnt stop jumping

#

@severe flame

severe flame
#

If you just set the speed and nothing brakes it, it will never stop πŸ˜„

viscid raft
#

How do I make it stop jumping?

severe flame
#

Do you have gravity enabled?

viscid raft
#

Yes

severe flame
#

Oh wait, the second line in your update, fixes the speed to the top once you jump one time

#

it always re-sets the last speed on the y axis

#

and you seem to never use that gravity modifier