No announcement yet.

Player-placable actor?

  • Filter
  • Time
  • Show
Clear All
new posts

    Player-placable actor?

    I'd like my my player to be able to place a turret actor in the world.

    The turret should spawn in front of the player and move where the player moves, until the player triggers it's placement in the world.

    I thought I should ask the community for any tips on how to go about this. Are there any tutorials or specific documentation that I should take a look at?

    Thanks in advance.

    I'll be working on something similar(not with a turret, but a skeletal mesh with physics asset) soon but haven't put much thought into how it will finally be implemented.

    I would imagine if we were to break it down into smaller pieces we could coordinate some core functionality(or at least what to expect).

    First, were going to need a scripted class for our spawn-able actor that links skeletal meshes, plays sounds, hold variable declarations and properties and other things like behaviors and states.

    Second, were needing to know the position of the player, this is easy.
    inside a function of our playercontroller class for example...
    var bool bCanConstruct;
    var vector NewConstructionLocation;
    var vector NewConstructionRotation;
    // need a way to visualize the turret position after adjustment before calling the following SpawnMyTurret function!!!!!
    exec function SpawnMyTurret()
        //simple bool check to enable/disable construction to keep it simple   
         if (bCanConstruct == true)
            `log("Player is able to construct");
            `log("ExampleCurrentLocation.Z" @ Pawn.Location.Z);
            NewConstructionLocation = Pawn.Location;
            NewConstructionLocation.Z = (Pawn.Location.Z - 50);
            NewConstructionRotation = Pawn.Rotation;
            NewConstructionRotation.Pitch = Pawn.Rotation.Pitch;
            //or if we needed pitch defaulted...
        //other code here if needed
    Third,instead of spawning the actor in position on execution, beforehand instead we need to fake it by possibly attaching a false 'placeholder" so that the player can "visualize where" the object is in the world, before it is committed for placement.
     whats a good way to do this?
    Fourth, there needs to be a method of confirming the placement: this could be a timer or some type of manual commitment via keybind.
     Above example used exec function/keybind
    Finally, the information about location and rotation would be accumulated based on the relative player location and the object physically instantiated and spawned into the world.
    //in the same function(or in another, not sure yet)
    spawn(class'Z_DWGS_ConstructTurret',,,NewConstructionLocation,NewConstructionRotation );
    From there animations and script should handle behavior.
    What do you think about this?

    Anyone else have any input or ideas or possibly some instructions on a known working method of completing this?


      Keybinding is easy, but how to make it re-usable?
      I personally would like to know how to listen for a particular keypress from within another function. Can this be done?
      Like the enter key to confirm placement and other keys like arrow keys for adjusting the object, prior to confirming placement with the enter key. This is something I alone require with the placement of my object.

      Any help and advice would be greatly appreciated.
      I always enjoy helping others.


        I was thinking of spawning the object in front of the player much like how 3rd person meshes are attached (i believe this is based from camera position). That way the player can look around to find a precise spot to deploy.

        I should have some time soon to put more thought into this.

        For your question regarding capturing key input: I'm using the following code in my PlayerInput class to capture key input and disable mouse clicks (for when in hud menus).
        //-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //Captures all keypresses
        //-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        function bool KeyInput(int ControllerId, name KeyName, EInputEvent IEvent, float AmountDepressed, optional bool bGamepad)
        		if(KeyName == name("LeftMouseButton") || KeyName == name("RightMouseButton")){
        			return true;
        	return(false); // Allow other interactions to process input.
        You should be able to use a similar approach to achieve what you need.


          Nice! I haven't had much time to follow up on some areas of unreal script study, I have not seen key input used in any of the classes I've read through while learning code. I must have completely ignored it somehow...
          Yes this is very much helpful indeed.
          Assuming this is correct, the same function can be tuned to listen for combinations of key inputs simultaneously and fire another function or script if conditional statement is true...
          I would imagine much is possible with this.

          I'm starting to understand more about how you plan to use your turret now, I assume in most case situations , the player is not going to have much time to deploy the turret as where my work of the functionality will be based on time/resource consuming construction and defense.

          Also what you said about the 3rd person weapon meshes and the camera position, as far as I know that is correct.
          I imagine all sorts or ways this could be done, just not obvious about what the best fit for each project each method would be.

          It could even be possible for you to approach the turret method as a type of short distance physics toss-able item. Where ever it comes to restitution, is where the mesh coords are stored and the item is spawned/deployed. How very interesting it is to toss ideas around.

          @Coldscooter: Thanks for sharing the snippet from your input class, it opened my imagination a bit regarding a few things.
          I'm still open ears to suggestions and ideas regarding this topic if you come across anything we haven't mentioned id love to hear about it.
          I'm sure others would appreciate reading through and finding inspiration in ideas being shared.

          Too many people out there have the mindset that someone is going to rip them off for ideas these days..
          Lets be honest, all the good aspects of games have already been done in one manner or another or are currently in development.

          Understanding them or learning the many ways they can be recreated/reinvented is no secret!


            You could make it a secondary gun you can carry, then just use key to deploy it and then use same key to pick it up