Forum rules - please read before posting.

Crouch able using AC controller?

I do not know coding. I really don't want to buy UFPS just for an adventure game using First Person.
I searched around and all the answers for Unity appear to be to code it into the Movement script and camera script to make sure everything goes back to normal after lowered for crouch.
I do not wish to try to modify a script to do this and mess it up.
Is there an easier way? There is 1 section in my game you have to 'crawl' to get to rest of the tomb....
I could find another gimmick but I would rather not. 

Comments

  • edited September 2016
    Well, if you are using first person, as I'm guessing from what you said, then maybe you could just animate the camera to move lower while you are crouching, then animate it back to normal once the crouching is done. You'll probably need to animate the size of your capsule collider too, though. Else the player will still collide with objects above the camera. Another solution to the collider issue would be to leave the player collider alone, but make sure your ceiling at the time of crouching doesn't have a collider, if you do this it would also be a good idea to make sure the player can't jump, or he could go through the ceiling...

    If you know some scripting, you could also reproduce the aforementioned behavior and tie to a button press or something. Mind you I rarely use first person so you'd have to try and see how well this options work for you.
  • Animating the capsule collider and camera position would work best if the point at which crouching occurs is at a very specific time.

    If you're looking for a more general "crouch anytime" system, then writing a custom motion controller or making use of UFPS would be the way to go, however.

    Is the crawling literally at just that point?  You could even create a separate Player prefab with everything amended, and then use the Player: Switch Action to swap out the active player prefab.
  • Yes, only at that point, but they need to go back through as well, both directions. 
    So would I do a trigger point and then Player:Switch just before they enter the crawl space then a trigger on other side with Player:Switch to go back to normal?
    If that is the case is there a way to use 1 trigger point to do both? If an side A I 'shrink', Side B I 'resize', when I enter from Side B can I set the same trigger with another action to check and switch or will I have to play the spacing game with 2 triggers on both sides? 
    Or better yet, can I activate a trigger by key press when in the area so I can use a trigger on each side and just press a button to do the character switch that simulates my crouch.
  • So I went with 2 triggers on each side.
    Made them narrow and reduced my player collider  so as not to cross both at the same time. 1 switches to the crouchplayer and the other switches me back to standing. I set both with a check first though. Not ideal but works for what I need it to.
    I'm sure I'll be asking lots of same or 'stupid' questions on this project but they should be fairly easy to answer, it is a linear adventure game with very little interaction. Just a learning project that I can call my own.
    So be prepared to help me!
    Thanks!
  • edited September 2016
    Hi, you could also try my custom trigger example which has separate slots for Actionlist assets for OnEnter and OnExit. You can the expand the trigger's size to create a zone/area where you want the player to start crouching. Once he leaves the zone the trigger can run the actionlist to return him to normal. I use a similar version for camera switching and opening and closing doors and stuff like that :)
  • edited September 2016
    The Demo scene uses a Trigger with two AC_Trigger scripts on it to show how the same Trigger can have both Enter and Exit functionality, but if you want to tie anything to a keypress you can use Active Inputs - see Section 2.14 of the Manual.

    You may want to change to an animation later on, following @Alverik's suggestion, but this'll be fine for now.  Just be sure to check Share same inventory? in your Settings Manager so that both player prefabs carry the same items.
  • Will do, I can't use a cutscene (I don't think) I need the player to have control since there is an object in this crawl space they will need to pickup.
    I will have to load up that scene in another project. (Which demo scene? The 3D one or the one with him in the basement movie studio or is that the same one?)
     I remove all demo scenes from any pack I install to keep file size down (I use source control and every little bit helps when updating)

    What I did do was first trigger:
     on enter player:switch CrouchPlayer (continue)
    then added another trigger and set to on exit player:switch InsidePlayer 
    Now when I enter it does switch to crouchplayer but when I exit it switches then switches to insideplayer then really fast back to Crouchplayer.
    I even tried adding a player:check and that made no difference.


  • @Alverik
    I tried your script but it didn't give me to property boxes to to put my action lists in, all it said was script name.
    I have no idea how to code so didn't know how to add an actionlist to the code.
    Your description made it sound like it would put CustomTrigger3D script and 3 boxes, 1 has the script we are running and the other 2 boxes for my action lists. but those boxes weren't there.
    I also need to figure out how to make an action list for enter/exit but I assume that would be fairly simple.
  • edited September 2016
    Ummm, you'll need to drop the script onto a game object for you to get options in the inspector. If you just click the script it will sometimes show if there will be slots when used but they won't be usable. When I said they are custom triggers, it's fair to say they are custom trigger's logic (or what will control the trigger). To actually use most scripts in Unity, you need to drag them and drop them on a game object. And this script is not an exception. You need to create a blank unity trigger and drop the script in that object. 

    It's actually pretty simple. Any object can be a trigger. All you need to do really, is add a collider component and tick the IsTrigger option,  and it'll immediately become a trigger, if the object has a renderer you can just disable it or remove it so that it becomes invisible (really, even your player could be a trigger if you want, as you're in first person, but triggers allow other objects to pass through them). You can check Unity's video tutorial about it here. It's a 3 minute video but you only really need to bother about the first 30 seconds. I guess, you could drop it in an AC trigger and it should still work, but that'd feel weird, lol. You could also check the demo and see how Chris made the AC trigger work two way too. 

    But, anyway, once the script is on any object, you will see the two slots for actionlist assets in the inspector (and one for the name of the tag to react to). Just remember that the script needs to be placed on an object with a collider with the Istrigger ticked, else it wont work (even AC triggers work that way).

    Alternatively, If the dropping/attaching the script thing confuses you, you can add the script to an object in a different way. Just click the object then, in the inspector, scroll all the way down and look for the button "Add Component", click it, and in the search bar that appears type the name of the script then click it from the list that shows up. Just do make sure the name of the script file is correct or Unity won't allow you to attach the script to any object.
  • edited September 2016
    That's what I'm saying, I dropped it onto the TRIGGER object in the scene and I didn't get the boxes to enter the actionlists into.
    I also dropped it onto just a game object as well and still no boxes to enter my actions into.
    Below is a video showing the 2 of the tests.
    I also tried with no actions attached then adding after the script and also added a box collider to the parchment object but nothing opened the 2 boxes on your script.
  • There are no 2 slots unless I did something wrong.


  • I went to try again now it won't let me assign the script, says I need to fix compile errors.
    ActionListAsset is the issue. I have tried everything I could think of.
  • edited September 2016
    Sorry, I misunderstood your previous post, it had me puzzled why it wouldn't show the boxes, so I assumed you were just clicking the script. But now I see, that appearance looks like a compiler error, alright. Anyway, I'm sorry, it seems I forgot to add it in the wikia, but it's most probably because your script doesn't have using AC; at the top. My actual trigger is much more complex, so when I copied it I mostly bothered copying the stuff that would help make a basic one for starters. I just wonder why you didn't get a compile error warning immediately? Mono should mark text as red when something is missing or wrong too (I use visual studio community though, and that one is a lot nicer showing you mistakes in the code). 

    Anyways, there's two ways to go about it there, either just put using AC; at the top of the script or add AC. to the lines: which have AdvGame.RunActionListAsset() in them, so that they read:

    AC.AdvGame.RunActionListAsset(...); 

    Else it won't recognize them (it needs to know adventure creator's namespace which is AC).

    Again, I'm sorry, I was convinced I had left AC. in the lines in the script, but my original script was using AC in more places so I guess I must have put the using AC; to makes things shorter when typing. Anyways, that was the very first wikia article, so I wasn't careful enough. Sorry, I'll amend it in the article. 
  • edited September 2016
    I was referring to the 3D demo game (in the Basement, yes).  It ought to work, but as Triggers depend on the shape/size of colliders, it may be that switching to a differently-sized player is causing the OnExit and OnEnter to run one after the other.

    Check that the two player prefabs have similarly-sized colliders in the X and Z axes.  It may be that you instead have to have two separate Triggers that are placed near each other, and have them both set to OnEnter.  To avoid the possiblility of both being run together, you can use the Object: Send message Action to turn a Trigger on or off.  If you do that, however, you will need to ensure there is a RememberTrigger component on each to ensure their "on/off" state gets stored in save game files.
  • Alverik...I had to do both, USE AC; and add AC. to the lines, now it shows the boxes with no errors.
    Now to figure out actionlists!
  • edited September 2016
    Cool, but, weird, usually, you should be fine with just either method... what Unity version are you using? I did hear one other person mention the same thing, but it's never happened to me... but, oh well, it's good to know you got it working :)
  • edited September 2016
    5.4.0f3 64bit

    Now having actionlist issues.
    can't find how to make one that will work on enter and exit. I can only figure out the actiontrigger when attached.
    Guess I should just check the demo scene and use his way instead. I am sure your way is easy but not when starting out, I need examples to learn usually.  
    I will figure out your way though sooner or later!

    ChrisIceBox:
    (The action trigger are you referring to is the one of switching cameras? I would just modify that one to work with switch player with whatever bool var I chose? or was there a different trigger you referring to?)
  • Mr IceBox!
    Ok, I tried to duplicate your 2 actiontriggers.
    I now have 1 local variable CROUCH=FALSE (as default)

    1 trigger:
    on enter 
    Variable:check...if crouch=false continue 
    Player:switch new player=crouch player after running=Continue

    2nd:
    on exit
    Variable:check...if crouch=false continue 
    Player:switch new player=Insideplayer after running=Continue

    Now it crouches on enter just fine, however when I exit it stays crouched.
    I even tried adding to the first trigger operation  a variable set crouch=true and chaning the 2nd trigger to variable crouch=true switch player but still won't work (that one actually freezes the game)
  • edited September 2016
    Eh? the whole point of the trigger is that you can use different actionlist for each slot, that way you can have two completely different sets of actions for each, saving you some headache. That way one will always be run when you enter the trigger, and the other when you exit it. There's no need to make a single actionlist asset which works for both states, that sort of beats the purpose of the script (no need for variables either, the trigger already knows if the player is inside the trigger or not)... but I do understand the feeling, I try to create as many ways to shorten the amount of actions I need to take to do some task. i.e: the trigger I use automatically changes cameras, opens prompts, changes HUD UI , pauses and unpauses the game if I want and I'll probably add more stuff to it later, though, I can't really share it, because it depends heavily on many of my other scripts which run along the game. It wouldn't really work without the rest and they do stuff really specific for my project. 

    But anyways, whatever works for you in the end is what counts.

    Now, about your question, I don't see how that would work, they're both testing for the same state. I don't know how you've laid out you actionlist, but it may be that your first trigger's actions are running first, so it takes precedence and always wins over the other (so the other never runs). Else they may even be triggering at the same time but one of them wins the race anyway. 

    In the first trigger, when variable check results false, you need to use Variable:Set and make the variable true, then change the player. Next in the exit trigger you have to check if it's true, if it is, then you can change the player again (and use Variable:check again to set the variable false again, else the player won't crouch ever again either). 

    If you are using a single actionlist asset, then you would need one Variable:check which then forks: if false = crouch, if true = standup. Just make sure to update the variable appropriately (think of the variable as a light switch, the variable:Set is you flipping the switch, and the variable check is a dude who is checking if the switch is on or off before doing something. He is always going to do the same thing if you don't flip the switch). 

    Anyways, once done you can plug the actionlist asset in both triggers.
  • Seconded about needing to have Variable: Set Actions in your Triggers, but if the Triggers are far enough apart that they can't be triggered at the same time, you probably don't need variables.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.