[VERY ADVANCED] Portal Physics Fluency

Discussion in 'Plugin Development' started by JBoss925, Aug 20, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    JBoss925

    Hey guys, I've always been a fan of the Portal video-game series and I decided to make it in minecraft. I have everything ready except for the physics in the game. Here's my problem, in the game dependent upon the orientation of the portal you enter and the portal you exit, your velocity is changed in different directions. There are 6 orientations and since there are 2 portals that means 36 different calculations would have to be made to match all the cases. What I propose to you is a better way to do this. I can see none, and before I begin work on 36 different calculations I ask if anyone has any idea what I can do. Thanks :D.

    P.S. I mean how your velocity carries when going through portals of different orientation.

    Drawing Representation:
    [​IMG]

    - JBoss925
     
  2. Offline

    The Fancy Whale

    I'm not sure I understand what you are asking... Sounds like you just need to create some objects and a method?
     
  3. Offline

    JBoss925

    No, I have all objects ready. Have you ever player portal? It's how your velocity carries when going through portals of different orientation.
     
  4. Offline

    The Fancy Whale

    I have not. You should try to explain how everything works. You are limiting yourself to developers who are very familiar with the game you are referring to.
     
  5. Offline

    JBoss925

    I drew a picture to illustrate my idea in the original post.
     
  6. Offline

    The Fancy Whale

    Create jump in portal event
    if (player velocity is downward){
    Change to whatever velocity}
    else if (velocity is sideways){
    }
    else if (velocity is upwards){
    }
    Something like that?
     
  7. Offline

    teej107

    Maybe have each portal object have an orientation variable (maybe an integer?) and then multiply/change the velocity based on the orientation?
     
  8. Offline

    JBoss925

    Yes, that's what I currently have to do. The problem is there are 36 different orientation possibilities. I just wanted to see if there was some other mathematical way to universally create vectors using given directions and velocities.

    That's how it currently is. There are 36 different combos though. I assume there must be some mathematical way to compute the velocities using given orientations.

    EDIT: I'm not expecting to find it though. Just seeing if anyone has ideas before I do all the computations.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  9. Offline

    The Fancy Whale

    Not seeing how there are 36 different possibilities? I see 6... But if there is a pattern to the orientations you can create a simple method. Not sure how the portals work.
     
  10. Offline

    JBoss925

    Yes there are 6, but since there is an entry and an exit portal, I must account for both values. First the entrance for the base velocities then the exit to change actual direction. 6 x 6 = 36.
     
  11. Offline

    The Fancy Whale

    Oh so the orientation of both the entry portal and the exit portal matter. Is there a pattern to the velocities?
     
  12. Offline

    JBoss925

    Not really. I'm thinking about having 36 orientation pairs and then have modifiers like -x, -y, z stuff like that.
     
  13. Offline

    Cycryl

    JBoss925 The Fancy Whale
    make a method that Switches the coordinates with each other depending on the direction of the protal
     
  14. Offline

    Deleted user

    JBoss925
    Get the blockface of the entry portal. Determine x,y, or z.

    Get the blockface of the exit portal. Determine x,y, or z.

    Replace the value of the x/y/z from the first velocity to the velocity after the exit.
     
    es359 and JBoss925 like this.
  15. Offline

    AoH_Ruthless

    JBoss925
    You need some sort of Directional class that retrieves whether or not a player is moving North, West, East, or South. You also need to have directions Up and Down. Cardinal Directions are based on Player Yaw, while Up/Down is based upon a player's start and end y coordinate.

    Now we can retrieve a player's direction at any given point at time (I'm not going to write the logic for it, see if you can figure this out).

    In a PlayerMoveEvent, there are two steps to trigger an entry through a portal. You will want to check if the to block does not equal the from block and if the to block is the location of the portal. Both conditions must be satisified (in order to prevent duplicate portal triggers). Now check if the Player is moving Up or Down, then add metadata such as "up" or "down" to the player (idk, up to you). Also, get their velocity with Player#getLocation()#getDirection() and store that, too.

    Likely the portal trigger results in a PlayerTeleportEvent. You will want to add metadata to the player in the PlayerMoveEvent for easy tracking. So, check this metadata in the PlayerTeleportEvent. Remember the stored velocity? We need that. If the direction is up or down (using that awesome metadata), modify velocity and return because we don't need anything else in the event.

    However, most likely a player was not going up or down but a cardinal direction. Now, the location of the Portal should be stored such that it has a yaw. Get the direction of the Portal based on this Yaw and retrieve its cardinal direction. Modify the player's velocity based on this cardinal direction, if they are not concordant.

    I hope this essay made sense and explained how to do it. It all works in my head, but I don't know if it will actually work when you put it to test, but try it :)
     
    es359, JBoss925 and Dragonphase like this.
  16. Offline

    SparrowMaxx

    this is way easier than people are making out. you don't need to know what direction the player is going. you dont need any metadata at all except for portal direction.


    When a player enters the portal, get their absolute velocity. That is, the speed they are going regardless of direction.
    player.getVelocity().length().

    Now you now how fast the player is going, you just need direction.

    Then, use the exit portal's orientation to determine direction. If the portal faces up, they move up. If it faces east, they move east. Create a unit vector in that direction and multiply it by the length.
     
  17. Offline

    JBoss925

    Yep that's what I'm doing. More specifically something like what zombiekiller753 said.

    And AoH_Ruthless that's exactly what I was planning to do. The only thing is there are 36 different calculation changes I must make in order to achieve the effect. So what I plan to do is create a PortalModifier enum with all 36 different combos in it and then in a separate computation class, change the x, y, and z values to match the portals. And yes, I'm triggering a PlayerCreatePortal, PlayerDestroyPortal, and PlayerPortalTeleport event.

    Though I'm not sure this will matter much longer...
    EDIT: No to that^!!! The Bukkit Community lives on!

    I also might turn this into a working Util once I'm done so people can create fluent physics.
     
Thread Status:
Not open for further replies.

Share This Page