Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Loading next scene on contact problem help please...

  • 07-03-2015 3:31pm
    #1
    Registered Users, Registered Users 2 Posts: 3,404 ✭✭✭


    Hay males & females im having this little problem and its really starting to annoy me, basically i have this scene which i split into two and i want the second part to load up when my player enters this specific area, im using java for it (why cause its all i could get to remotely work)

    #pragma strict

    function Start () {

    }

    function OnTriggerEnter () {

    Application.LoadLevel("1B");

    }

    The problem im having is it only works when i have a rigid body on the box collider, but it loads the next scene when ever the game starts and not when the player contacts it, but when i have the rigid body off nothing happens, if i put the rigid body on the player nothing happens either. im a tad confused.

    probably a simple fix but i have zero coding experience and ehmm a bit lost at the moment
    any help would be appreciated thanks

    got some updates on my blog about it and a this video if you fancy a gander at it,with awfully low audio



Comments

  • Registered Users, Registered Users 2 Posts: 3,831 ✭✭✭Torakx


    void OnTriggerEnter2D(Collider2D other)
    {
    switch(other.tag)
    {

    case"Ground":

    grounded = true;

    break;

    }


    }
    Here is one I copy pasted from my code for a 2d character controller I made.
    Using C#.
    I think your issue is that your code is saying as soon as the collider is triggered, load the scene. If the ground has a collider and the player has a trigger, he only need to touch the ground to load the scene....I think.

    I never use javascript but I'l try fix the code or close enough anyway.

    #pragma strict

    function Start () {

    }

    function OnTriggerEnter (Col Other)
    {

    switch(other.tag)
    {
    case"ObjectTagHere":

    Application.LoadLevel("1B");

    break;

    }


    Switch cases are useful to make several different tagged objects act differently to colliding with your character for example.
    Every case inside the switch has the tag of the object you want to collide with, the function this object does on collision with said other object tagged and a break.
    After the break you can just copy past another case and break to do more of them. they stay inside the brackets of the switch statement.

    Your issue I believe is the OnTriggerEnter(col Other). Where you have no col other stated.
    Hope that helps some.

    Nice anims and scene by the way :)


  • Registered Users, Registered Users 2 Posts: 454 ✭✭Kilgore__Trout


    Also, if you are encountering unexpected behaviour, try popping in a debug statement to get a little more info on what is causing the problem. Environment looks really interesting. Keep us posted : )

    function OnTriggerEnter (Col Other)
    {

    Debug.Log("Scriptname.OnTriggerEnter. Object with tag " + other.tag + " has entered collider");

    switch(other.tag)
    {
    case"ObjectTagHere":

    Application.LoadLevel("1B");

    break;

    }


  • Registered Users, Registered Users 2 Posts: 3,404 ✭✭✭Lone Stone


    Thanks for that reply torakx & trout still doesnt seem to be working for me, i think it might have to do with my character controller using raycast's maybe. the code in the op seems to be working for other people but not me hmm its just some thing i found on youtube.

    /head + wall


  • Registered Users, Registered Users 2 Posts: 3,831 ✭✭✭Torakx


    You could try use pastebin to post your code for the controller.
    If the object that triggers the scene has a normal collider with notrigger and is tagged. Then the character would need a trigger collider with that code. It should work then as far as I know.
    I often have a character with a normal colider and a trigger collider(triger collider slightly larger). Not sure if thats the right wayto dothings, but it always worked ok and gave me plenty of options.

    What are you using the raycast for?


  • Registered Users, Registered Users 2 Posts: 3,404 ✭✭✭Lone Stone


    Well i use this asset i bought ages ago for my player controller has al the code for the platforming parts, http://u3d.as/content/jna-mobile/2d-platform-controller/4hm it uses raycast's i couldnt around the sprite for detecting where the feet and things are

    it does have a 3d one that you use your actual mesh in so i dont think that requires raycasts but i intend to render out my sprite sheets so i went with the 2d one. I insanely lost when it comes to this stuff ugh i need to do a coding course or something.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,831 ✭✭✭Torakx


    Hmm, that's a little tricky.
    I try not to use other peoples controllers for this reason. It can turn into a nightmare if you don't understand fully what is going on with their code.
    I often find it difficult to manipulate built in controllers and just write them myself.
    Of course they are nowhere near as good as the other ones, but I do have fullcontrol and knowledge of whatis going on. Which I think is a safer bet overall.
    Not sure what to say to that moving forward though.
    It's difficult to solve that issue from a description. It could be so many things.
    I have spent hours trying to fix a problem and it has ended up being something silly like an object not tagged LOL

    You could try disable the controller and use a basic one for movement. when you get the scene change working and understood, you could then try bridge that gap again.
    I could share one of my many controller scripts. I write a new one for every game lol
    But again, it would have variables and stuff going on that is related to the game and the type of control I wanted.

    If you script works fine and that new code doesn't show any errors, but doesn't do anything, I am inclined to think the issue might be inside the unity setup (tags, something not check on or off etc).


  • Registered Users, Registered Users 2 Posts: 3,404 ✭✭✭Lone Stone


    what il do is i shall try using one of the ones that come with unity on a cube or some thing with some of the above code and see if that it works that way, then il i know if its my bloody raycast set up which it seems like it could be at this stage feck sake !! why cant things just go smoothly for me:( fatal out memory errors are all the rage today when i try make a build to woop ... .. .

    thanks for the help !


  • Registered Users, Registered Users 2 Posts: 454 ✭✭Kilgore__Trout


    Hey, not the cleanest solution, but if you want to get it up and running, and come back later, it might let you away.

    You could just disable the trigger collider if it is causing problems, and attach a script to the player or level exit object that does a distance check every second. If the distance is below a certain threshold, just load the level.

    if(Vector2.Distance(playerVector, levelExitObjectVector) < 1)

    (Vector3.Distance if using 3d)

    I ran into some performance issues with a lot of trigger colliders continually entering and exiting one another. Could probably have reduced the overhead with layers, but ended up replacing a lot of the colliders with timed distance checks.


  • Registered Users, Registered Users 2 Posts: 3,404 ✭✭✭Lone Stone


    I think il spend a week trying to set up the player with playmaker instead of this 2dpc package ive been using, it was easy to set up but then it just gives me a trouble with simple things.

    I'l throw it out there since im here, i would love some help on this if anyone would be interested just a sort of side project if anyone is interested, to date ive just been making it in my spare time and its mostly just been from ideas floating around in my head and little doodles, but if anyone is interested il put together a production booklet pass it on if your interested, il take care of the visual side of things & story or collab on that, im open to things. could share the project drop box or some thing. Would love it turn out to be a nice little side scrolling rpg light platformer type of game and if it ends up being profitable that would be cool and obviously split any profit if it gets to that stage, so if anyone is interested send me a pm and we can talk about it.

    yeap thanks.


Advertisement