Ability to fly code\osp

Users who are viewing this thread

Alex35562

Recruit
I'm trying to create mod for Warband in the style of a sea fantasy. I need to give the player ability to swim in and under water. I was thinking of adapting some kind of osp flight code to this, but it turned out that no one had really created it over the years.

I managed, for example, to speed up the player when he is in the water at a certain depth, but this is just running underwater, and not swimming to different depths, of course.

I've tried using the jetpack take-off and descent animation from the Bear Force mod and it generally works, but I don't know how to make the player stay at a certain height all the time in this animation rather than flying up or down.
I also tried to create a scene prop under player to then try to move it using separate keys, but it doesn't look very reliable and I don't have enough knowledge for that. This guy seems to have done something similar, but I haven't found his osp anywhere, or at least his mod.
Also in this topic (https://forums.taleworlds.com/index.php?threads/flying.132909/), another guy, according to him, successfully did almost the same thing, but also did not want to post the code.
Can someone help me? Can you show me some code suitable for me? or at least just tell me which direction I need to move in?
 
Flight is best achieved by turning off the agent's collisions and scripting the movement via keys with collision checks. I typically use animations to mark the state of an agent as flying, but for swimming you just need to check that they are below water level.




I whipped this up based on my Fate/ OSP code combined with the collision checks from my Obi Wan demo.

Python:
fate_flying = (0, 0, 0, [
    (set_fixed_point_multiplier, 100),

    (get_player_agent_no, ":player"),
    (neq, ":player", -1),
    (agent_is_alive, ":player"),

    # It would be responsible to split this off and mark the player as swimming in a different trigger, I was just lazy for testing
    # Maybe pressing jump under a the waterline to put them into swim mode, that will make it easier to do per-scene water levels and such too
    # and prevent bugs with that awkward transition from swimming to walking
    (agent_get_position, pos2, ":player"),
    (position_get_z, ":altitude", pos2),

    (assign, ":pass", 0),

    (try_begin),
        (le, ":altitude", 100), # Below Water level
        (agent_set_no_dynamics, ":player", 1), # Make them no longer affected by collisions (flying)
        (assign, ":pass", 1),
    (else_try),
        (agent_set_no_dynamics, ":player", 0), # Re-enable their collisions
    (try_end),
  
    (eq, ":pass", 1),
],
[
    (set_fixed_point_multiplier, 100),
    (get_player_agent_no, ":player"),
  
    (agent_get_look_position, pos2, ":player"), # This will enable mouse controlled flight
    (copy_position, pos3, pos2),    # Cast ray pointer
  
    # We're going to use this to split the speed vector to the movement axises to prevent zooming on a 45 degree angle
    (assign, ":move_x", 0),
    (assign, ":move_y", 0),
  
    (assign, ":speed", 2),    # This is CM per frame, 5 is surprisingly quick, didn't test 2

    (try_begin),
        (try_begin),
            (key_is_down, key_w),
          
            # Cast ray is a can_fail, meaning that if it does not collide, it will continue to the next block, moving the position
            (try_begin),
                (cast_ray, reg0, pos50, pos3, ":speed"),
            (else_try),
                (assign, ":move_y", 1),
            (try_end),
        (else_try),
            (key_is_down, key_s),
          
            (position_rotate_z, pos3, 180),
          
            (try_begin),
                (cast_ray, reg0, pos50, pos3, ":speed"),
            (else_try),
                (assign, ":move_y", -1),
            (try_end),
        (try_end),
    (try_end),

    (try_begin),
        (try_begin),
            (key_is_down, key_a),
          
            (position_rotate_z, pos3, -90), # Never really checked if these are correct, ngl
          
            (try_begin),
                (cast_ray, reg0, pos50, pos3, ":speed"),
            (else_try),
                (assign, ":move_x", -1),
            (try_end),
        (else_try),
            (key_is_down, key_d),
          
            (position_rotate_z, pos3, 90), # Never really checked if these are correct, ngl
          
            (try_begin),
                (cast_ray, reg0, pos50, pos3, ":speed"),
            (else_try),
                (assign, ":move_x", 1),
            (try_end),
        (try_end),
    (try_end),
  
    (assign, ":a_move_x", ":move_x"),
    (assign, ":a_move_y", ":move_y"),
    (val_abs, ":a_move_x"),
    (val_abs, ":a_move_y"),
    (val_add, ":a_move_x", ":a_move_y"),
  
    (try_begin),
        (gt, ":a_move_x", 0),    # Prevent division by zero errors
        (val_div, ":speed", ":a_move_x"),
    (try_end),
  
    (val_mul, ":move_x", ":speed"),
    (val_mul, ":move_y", ":speed"),
  
    (position_move_x, pos2, ":move_x"),
    (position_move_y, pos2, ":move_y"),

    (position_get_distance_to_ground_level, ":altitude", pos2),
    (position_get_z, ":true_alt", pos2), # will prevent fall damage, trust me
  
    # This has dual purpose, prevent hard to predict clipping errors and keep the player from being stuck inside the ground
    # This bit is still buggy, I was using it to limit to flying characters to a much higher distance from the ground
    # and with the swimming transition being automatic, it doesn't really like the character being boosted up like this
    # at the "shore"

    # I would recommend making the swap to swimming being player controlled and just prevent them from hitting the ground while swimming
    (try_begin),
        (lt, ":altitude", 10),
        (le, ":true_alt", 550),
        (store_sub, ":change", 10, ":altitude"),
        (position_move_z, pos2, ":change", 1),
    (try_end),

    (agent_set_position, ":player", pos2),
])

The fate code linked demonstrates animation switching, which will be useful for this.

Edit: I just realized holding both back and a direction will cause incorrect collision checks, you might wanna fix that.
 
I saw your comment on the YT video, thank you for the kind words!

Information should be shared freely!

As much as I prefer the forums for stuff like this, if you're a discord user, the modding discord is still really active and has a lot of talented souls who are pretty much solely there. Might be a good place to pick the brains of other people for systems like this
 
I saw your comment on the YT video, thank you for the kind words!

Information should be shared freely!

As much as I prefer the forums for stuff like this, if you're a discord user, the modding discord is still really active and has a lot of talented souls who are pretty much solely there. Might be a good place to pick the brains of other people for systems like this
Oh, good idea. Thanks again!))
 
Back
Top Bottom