Announcement

Collapse
No announcement yet.

Creating A Custom non-wheeled Movement Component via BP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Creating A Custom non-wheeled Movement Component via BP

    This is starting to make me want to learn Unreals c++ API, the lack of real-time debugging is what holds me back. Anyways.

    My studio is creating a submarine simulator game with the community ocean plugin as the base.

    We want to have as many as 10 classes of ships the player can control, and of course there will be dozens of enemy ships that can change speed, accelerate away from torpedoes in range etc. We have a working controller for one class of submarine but its tweaked with someting like 40+ variables to get it just right. So I thought. Why not make a custom component that works as an "engine" that can be re-used over and over again; modularity.

    So I start with just getting a basic "ahead flank" (war power, 110% engine power basically). Using the add actor local offset with an x of say +50 got me the right speed, but it instantly speeds up to that rate.

    So I tried using some of my Unity knowledge to use just vector3'sor 3Vectors whatever Unreal calls them to make it accelerate at a certain rate to top speed and then continue at that speed. I got as far as the picture below before giving up after a few days of experimenting. I'm using the scene component base class as you can see from the top.

    What might be the best way to get any ship this is attached to to accellerate at a rate defined by a variable flank_speed_accell at x cm/s up to max_speed_flank or on the opposite end back_slow_accel at -x cm/s up to max_backslow_speed. Using the vector method you see I was able to get it to accelerate, get up to speed, but then it would slow down at the same rate and stop as it reached its VInterpTo target. I traced this problem down to the fact that the target was for whatever raeson basically the world origin (something like (1.5,0.5,0.5 reletiev to the world) so it would basically deaccellerate just before getting to that point and then stop dead in its tracks there. When I changed the target for VInterpto to get actor location + vector (50,0,0) with an interp rate of I think 1 or 2 set manually it did the exact same thing as when I just used a single AddActorLocalOffset(delta=50,0,0) node so it instantly starts moving at 50cm/s.

    How can I accelerate using that node smoothly, or is there a better way to do it, or was I having the right idea using vectors and AddActorLocation?

    TLDR: Im trying to make a reusable 'engineMovement' component that is used for propelling a ship in its positive and negative x direction. (Forwards and backwards) and be able to use it on any class of ship. Should I be using an empty actor class? It seems im limited in what BP nodes I can use with the scene component class. The main reason behind doing this is so that we dont ahve to write a custom controller for each calss of submarine/boat because a) its extremely messy (huge event graph, nested macros, tons of functions, tons of variables that im sure take up huge amounts of memory allocation), just looking towards saving time in the future.

    I'll add as usual that I came to UE4 from Unity Nov. 2014 but after realizing I didnt have the time or skills to code using unreals API (My C++ is rusty and not having live debugging makes development very very slow), so I'm kindve missing the modularity of writing a script, then adding it to a gameobject (actor) and tweaking its public variables on a per gameobject (actor) basis in the editor.

    The modularity is what im missing, but forgiving that, I'm having a hard time making a ship slow down and speed up nice and smoothly. I can account for drag and stuff later. Its tough because I cant just hold the throttle down I need to be able to have an input event cause the 'engine' to go x speed (certain RPM really, but it gets the boat to x speed over y seconds)

    Heres one of the images I took while I was messing around. I'm having a hard time finding any info for non-wheeled or ship baaed vehilcles. Everything is either wheeled, non gravity (space), throttle controlled or a mix of 2 or 3 of the former.

    Click image for larger version

Name:	6xg2NTl.png
Views:	1
Size:	430.8 KB
ID:	1147482

    Thanks. I've really been learning alot about UE's BP API. The community here is great. The documentation is whats lacking. I intend to start writing documentation down with blueprint examples on my website or a nice e-book for un-common tasks like this. I cant just slap a playermovement component on our pawn based submarine and pawn based AI enemy ships.

    Edit: This function is getting called every tick as soon as I activate it in the component owners BP using an action mapping event (a key press event) also everything except current_speed has default values that dont change anywhere else, infact they are all local values except time.deltaTime that is the very first variable set from EventTick(deltatime). Should that maybe be calculated every frame in the owners BP and then cast and get or is it fine the way I have it set to calculate forward velocity?
    Last edited by Nsomnia; 04-04-2015, 01:45 AM.
    Tek LLC a personal Candaian Company running BlenderTek & UnrealTek is currently looking for help to bring back submarine simulator gaming with a new genre of sub sims: Cold War! (1945-1991) Operation: Trident SubSim Dev Diary Thread - Donations

    #2
    Could you use a timeline?

    Narg
    http://www.seven-mountains.eu/

    Comment


      #3
      Originally posted by Narghile View Post
      Could you use a timeline?

      Narg
      I read one post on AnswerHub where someone suggested that, but it was for AI using go to location I beleive. I've never used timelines before. I thought they were used to create a series of functions executions in certain orders for certaain times?

      Can I adjust the values in a timeline for example for every second in the timeline the AddActorLocalOffSet(Delta(x,0,0) would go up by say 1.1x until it reaches max speed? Is that possible with a timeline, I've opened it before, just never used it in any logic.

      Edit: I should add heres a quick video I took of the genreal layout and the effect I was getting. It worked nice, just the target destination was basically the world origin as you can see.
      Last edited by Nsomnia; 04-04-2015, 02:06 AM.
      Tek LLC a personal Candaian Company running BlenderTek & UnrealTek is currently looking for help to bring back submarine simulator gaming with a new genre of sub sims: Cold War! (1945-1991) Operation: Trident SubSim Dev Diary Thread - Donations

      Comment


        #4
        Timeline basics, is just increasing or decreasing over set time.

        For example, in a time line I can get a number to go from 1 to 60 over 60 seconds.

        That then comes out of a node on the time line as a float.

        So if you had speed of 60, you could get speed and add the output from the timeline and add to current speed.

        So after 10 seconds you would be traveling at 70.

        You can also stop it, reverse it, start at a different times.

        Here is a timeline that goes from 0 to 10 over 5 seconds.

        Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	36.7 KB
ID:	1071884

        You can also set it like this, so a little slower at begining and end

        Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	31.3 KB
ID:	1071885

        Example speed increase

        Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	42.4 KB
ID:	1071886

        But timelines can do far more than this.

        Narg
        http://www.seven-mountains.eu/

        Comment


          #5
          Yes, you could use that output to increase health, change a vector, anywhere a value could be used
          http://www.seven-mountains.eu/

          Comment


            #6
            Goodness me I thought it was basically a sequence where you could delay firing. I wll try that out asap! If this works my partner who designed the alpha version is gonna feel like an idiot hes the one who is supposed to know about UE4 LOL.
            Tek LLC a personal Candaian Company running BlenderTek & UnrealTek is currently looking for help to bring back submarine simulator gaming with a new genre of sub sims: Cold War! (1945-1991) Operation: Trident SubSim Dev Diary Thread - Donations

            Comment


              #7
              IT appears you cant use timelines on scene components so I'm trying to figure out another class I can use timelines on that I can attach to my vehicle BP as a component. Using an actor class doesnt work cause you cant add an actor class BP as a component obviously. If I create a BP Component Script with parent class Actor Component it doenst allow timelines, jsut the same as scene component.

              Any ideas on ways around this or am I stuck to building a custom engine setup for each of the many classes of boats in the US and Russian Navys?

              Edit: OK so I made an BP called 'EngineTest' which is of class Actor. In its BP I made a function 'NewFunction0' that simply PrintString > Hello; when called, as well as on event begin play another printstring that says "EngineTest says hello"

              I then dragged this actor BP enginetest onto my boat pawn in the world outliner.

              Then on my boat, I took an event action "AheadFullSpeed" which when pressed goes to Cast to EngineTest class of class EngineTest. If that cast fails it prints cast failed ssn571 :: enginetest. From that enginetest class cast I then spawn an actor of that class with a transform of 0,0,0 0,0,0 1,1,1 then from that return value I call the function NewFunction0. When I start the game and prses the key bound to 'Aheadfullspeed' It first prints enginetest says hello, and then hello.

              Am I going in the right direction, since I can use timelines in that actor class?



              Thanks guys! I feel like im learning, I've only done regular casts before, and never spawned an actor.

              Heres a pic.


              Edit2: Ok tried moving the actor class 'enginetest' that is child actor of my vehicle. It moved the component (verified this by adding a static mesh to the heiracy of 'enginetest' and I see the static mesh move, but not my vehicle. I'm going to see if I can 'get actors of class' and use that, but it kinda defeats the purpose. is there anyway to autoweld (ive seen that option somewhere) an actor class BP to its owner of which its a child actor?


              In the pic below you can see in the distance the static mesh that moved which is the static mesh i attached to 'enginetst' actor BP which again is a child actor of the BP for the boat in the foreground which has the cast above.

              Click image for larger version

Name:	KX4TvfM.png
Views:	1
Size:	945.3 KB
ID:	1071912

              Whats extremely odd is even if i disconnect all the exectution pins in the function that moves the actor in its own BP and all the movement nodes, it still moves the actor... oh waitI thin I figured it out, its spawning the actor at 0,0,0 in reference to the world. Not to what its attached to. How can I spawn/activate it at the BP its attached to's origin and then 'weld' them together?


              Edit again: So I created an interface called 'enginetest_interface' and added it to my pawn's BP. Then in the actor based BP 'enginetest' on event begin play I use 'GetAllActorsWithInterface(enginetest_interface) and take the first one returned and set it to an actor variable. I then use that to move the ship pawn

              Now everytime I call this function from my ship pawns bp it moves 500 units instantly. Perfect. Up next... timelines! PS. Is getallactorswithinterface or getallactorsofclass the easiest way to implement this so I can reuse this engine on every submarine by just tweaking the values for each one, and then creating the same blueprint just slightly different and simpiler for enemy boats? (Or is there an easier way?)

              Click image for larger version

Name:	p9EIvBR.png
Views:	1
Size:	117.8 KB
ID:	1071915

              This may be more mess than is needed. It might be easier just to build a huge BP with an engine for each class of boat that will be spawned into the game... but I wanted to try modularity NCC (never copy code)
              Last edited by Nsomnia; 04-04-2015, 12:34 PM.
              Tek LLC a personal Candaian Company running BlenderTek & UnrealTek is currently looking for help to bring back submarine simulator gaming with a new genre of sub sims: Cold War! (1945-1991) Operation: Trident SubSim Dev Diary Thread - Donations

              Comment


                #8
                I got it to work so that when I say "Max speed" it accelerates from 0 (0 seconds, 0 value) to top speed (10 seconds, 10.4 value) then stays there at 10.4 cm/s

                Now I have to figure out when I say "Standard speed" how to stop that linetime and deaccelerate to standard_speeds's timeline end (top speed)


                Or when I turn the boat (we use the rotatormovement component), how do I tell it to slow down to a certain speed on the timeline (say timeline 6 seconds value 7.75) and turn the boat. Its such a new concept... I'll have to see if theres any youtube tutorials. UE4 is so new but im NOT going back to Unity.
                Last edited by Nsomnia; 04-04-2015, 04:06 PM.
                Tek LLC a personal Candaian Company running BlenderTek & UnrealTek is currently looking for help to bring back submarine simulator gaming with a new genre of sub sims: Cold War! (1945-1991) Operation: Trident SubSim Dev Diary Thread - Donations

                Comment


                  #9
                  I did a bunch of fooling around with timelines to get a smooth running tank with deceleration all the way into reverse. I may be able to help, but I do not have very good blueprint knowledge and use a lot of nodes!

                  Explain a bit what you are trying to do movement wise so I understand!
                  Last edited by docjor; 04-09-2015, 12:00 AM.

                  Comment

                  Working...
                  X