Constrain Actor To Corner Of Screen When Camera Rotates???

Hello All,

So basically in my game the camera rotates. I have an actor that I want to stay in the bottom left of the screen all the time no matter what. How to achieve this???

Thanks in advance!!!

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2014

    You lose points for not saying what size scene you have / the target device, the size of the actor, the exact position of the actor and all that . . . . :p :)

    So, assuming a 100 x 100 pixel actor in a landscape iPad project use this:

    Constrain X positon to -500 *cos(- scene.Camera.Rotation +35)+512

    Constrain Y positon to -500 *sin(- scene.Camera.Rotation +35)+384

    Constrain Rotation to - scene.Camera.Rotation

    Important: Ensure this actor is placed above the camera control in the layer order.

  • SocksSocks London, UK.Member Posts: 12,822

    Example . . .

  • SocksSocks London, UK.Member Posts: 12,822

    Actually this might be less confusing as it dumps one of the negatives . . .

    Constrain X positon to 500 *cos(- scene.Camera.Rotation +215)+512

    Constrain Y positon to 500 *sin(- scene.Camera.Rotation +215)+384

    Constrain Rotation to - scene.Camera.Rotation

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2014

    Getting a little more 'universal' . . . .

    Constrain X positon to (scene.Camera.Size.Width /2) *cos(- scene.Camera.Rotation +215)+ scene.Camera.Size.Width /2

    Constrain Y positon to (scene.Camera.Size.Width /2) *sin(- scene.Camera.Rotation +215)+ scene.Camera.Size.Height /2

    Constrain Rotation to - scene.Camera.Rotation

    . . . . . .

    You can add some value (XXX) to the multiplier to control the radius like this:
    (higher values push the actor away from the centre of the screen and more towards the corner).


    Constrain X positon to ((scene.Camera.Size.Width /2)+XXX) *cos(- scene.Camera.Rotation +215)+ scene.Camera.Size.Width /2

    Constrain Y positon to ((scene.Camera.Size.Width /2)+XXX) *sin(- scene.Camera.Rotation +215)+ scene.Camera.Size.Height /2

    Constrain Rotation to - scene.Camera.Rotation

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    @Socks said:
    You lose points for not saying what size scene you have / the target device, the size of the actor, the exact position of the actor and all that . . . . :p :)

    Dang it @Socks, I apologize and I will be a man about it and accept my lose of points! :p LOL

    Thank you for taking the time to post those. Right now I am running it in iPad Portrait but plan on it being universal. It will always be in portrait. The size of the actor is around 120x75. It's position I need it to stay at is X-450, Y-1093.

    I'm gonna see what I can try and hopefully get working!

    Thanks again!

  • SocksSocks London, UK.Member Posts: 12,822

    @KillerPenguinStudios said:
    It's position I need it to stay at is X-450, Y-1093.

    I thought you wanted to keep it bottom left ? These coordinates place it horizonally almost cented and vertically just off the top of the screen !

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    @Socks said:
    I thought you wanted to keep it bottom left ? These coordinates place it horizonally almost cented and vertically just off the top of the screen !

    Hey @Socks‌,

    So another thing is that the camera's Y position has 3 different places. Start menu, camera's Y position is 512.12, For gameplay, camera's Y position is 1536.12, and for end game, camera's Y position is 2559.12. It's X position the whole time is 389.641.

    The only time the player sees the actor is when camera is at 1536.12 (Gameplay) which will then be the bottom left of the screen. Hope that makes more sense now and sorry for the confusion.

    I attached a quick simple example of where the camera is at depending on it's position. Hope that helps also! Thanks again for helping out!

    https://dropbox.com/s/wceikjkn0bmaurd/CameraPositionExample.gameproj.zip?dl=0

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    Hey @Socks‌,

    Did you get a chance to see where I was wanting the actor to stay placed???

    Thanks in advance!!!

  • colandercolander Member Posts: 1,610
    edited December 2014

    You said your camera rotates do you mean scrolls? If is is scrolling the attached modified example does what you want. It will become visible as soon as the attribute "Camera_Positions" is set to 3 if this is not the desired effect you can unlock the actor and set its alpha visible to the camera's y position. The HUD actor is on a non-scrollable layer above the background layer.

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    Hey @colander‌,

    Let me be a little more specific, lol :p

    The camera does scroll as well as rotate. When camera is at position 1 the camera does NOT rotate. It's rotation is set to 0. When the camera scrolls to position 2 it rotates in random directions using the interpolate behavior. Then when camera scrolls to position 3 it no longer rotates and it's rotation is set back to 0.

    When the camera is at position 2 where the rotation occurs, this is where the object is seen and needs to be constrained to the bottom left corner even when the rotation occurs.

    So to reiterate, the camera scrolls between positions 1, 2, and 3 and the only time the camera rotates is at position 2. When it's at either position 1 or 3 there is NO camera rotation occurring and the camera's rotation is at 0.

    Hopefully that makes more sense to what I am trying to accomplish. Sorry that my initial comments and responses were too vague @Socks‌ and @colander‌. Hopefully this will allow people to see what I am trying to accomplish and there is a way to accomplish it! LOL :p :#

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    Maybe @Braydon_SFX‌, @pinkio75‌, @DeepBlueApps‌, @tatiang‌, @gingagaming‌, @jamie_c‌, @StormyStudio‌, @The_Gamesalad_Guru‌, @RThurman‌ someone else here on the forums knows how to go about accomplishing this.

    Tagged some of the ones who might know how to accomplish this and not sure if you guys have seen my post. I'm about 80-85% complete with my project and this is a big part I need, LOL Thanks in advance everyone!!!

    Thanks and Merry Christmas!!!

  • BBEnkBBEnk Member Posts: 1,764

    Seems using @Socks‌ examples all you would need to do is track the cameras position using a constraint, and then you could rotate at any point. So just change the 512 and 384 to attributes and constrain there location to the cameras center.

  • BBEnkBBEnk Member Posts: 1,764
    edited December 2014

    @KillerPenguinStudios‌

    Here I modified @colander‌ template.

    camera will start rotating on 2 but stop on 1 and 3.

    Theres a second camera actor on scene left bottom unlocked, and on a side not I just learned how to do this reading @Socks‌ examples above. I'm terrible at math,lol.

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    Hey @BBEnk‌,

    Thanks a bunch!!! I seem to have got it working for the most part. The only thing now that is giving me an issue is when the rotation is occurring the button is staying in the bottom left corner like it's suppose to but jerks and jitters like it's moving but snapping back into it's position. Hopefully that makes since.

    @BBEnk said:
    KillerPenguinStudios‌

    Here I modified colander‌ template.

    camera will start rotating on 2 but stop on 1 and 3.

    Theres a second camera actor on scene left bottom unlocked, and on a side not I just learned how to do this reading Socks‌ examples above. I'm terrible at math,lol.

    This thing has been killing my head lately! LOL I'm bad at math depending on what it is and sin and cos is one of them, lol

    Thanks again!!!

  • BBEnkBBEnk Member Posts: 1,764

    @KillerPenguinStudios‌

    I just tested again and button stays perfectly still very smooth. But if you have changed the order of the actors that can cause things to get jittered/jumpy.

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    Hey @BBEnk,

    Sorry for the confusion, I was referring when placing everything in my project. In the project you made for me it is smooth and stays still. When placing everything in my project, that's when I get the jittery/jumpy thing going on constantly.

    I made sure order, size, attributes, x and y and everything matched with yours which it all does but still getting it.

  • BBEnkBBEnk Member Posts: 1,764

    I can't really know without seeing your game,But it sounds like something is out of order. Your Button will need to be higher in the layers then the camera constraints.

  • SocksSocks London, UK.Member Posts: 12,822

    @BBEnk said:
    I can't really know without seeing your game,But it sounds like something is out of order. Your Button will need to be higher in the layers then the camera constraints.

    Screenshot of the layers (all the layers) would be useful in resolving this.

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    @BBEnk said:
    I can't really know without seeing your game,But it sounds like something is out of order. Your Button will need to be higher in the layers then the camera constraints.

    Hey @BBEnk,
    that's what I was thinking too but I have made sure the button was higher and I even tried different places in the layers to place the camera constraints and still no luck.

    I posted screen shots of my layers below. Thank you again for all your help!!! It is extremely appreciated!!!

    @Socks said:
    Screenshot of the layers (all the layers) would be useful in resolving this.

    That's what I was planning on doing but got home late last nigh. LOL I'm attaching 2 screen shots that show all the layers.

    So in the layers, the top 2 actors are the ones using the rules. Actor 1 is the button that stays in the bottom left corner and Camera_Controls2 is the one that has the other rules in it. I kept it below Actor 1 and tried it in different places in the layers but still getting the issue.


  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    Hey @BBEnk‌ and @Socks‌,

    So right after I posted the above post I realized that maybe I should try placing the button (Actor 1) in a different spot in the layers. When doing so I worked as it should. I realized that the button (Actor 1) can't be the first/top thing in the layers. If it's in the 2nd position or lower it works right. The further down the list the better it works.

    GRrRRrRrRr!!! So annoyed!!! Sorry for dragging you guys along with such a simple fix. Feeling like a real dumb dumb now. LOL But again, thank you for your continuous help and thank you @colander‌ for helping out as well! Again, I can't thank you guys enough!!! Wish I could take you guys out for a coffee or something. With out your guys help, this feature may have just been dropped from my game!!! Thanks a million guys and Merry Christmas!!!

    Can't wait to show off my new game to everyone!

  • colandercolander Member Posts: 1,610

    No worries happy to help, glad you got it solved and have a merry Christmas.

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    Hey @BBEnk‌,

    Hope you had a great New Year. Sorry to bring this post back up but I got another question in regards to this same thing except now I need to keep it placed in a different location as this is in regards to a new actor. I need the X to be the center of the point of the screen but the Y needs to be at the top but low enough for an ad bar to be placed at the top of the screen. I have been trying a bunch of things the last 2 days but no luck so feel it's time to ask for help. LOL

    So in my game I will have 2 different actors essentially doing the same thing but in different locations. On actor bottom left like we already have then another actor center and near top.

    Thanks in advance for your help!!!

  • BBEnkBBEnk Member Posts: 1,764

    In the previous example 55 is just a position around a diameter so 55 = lower left for top center you would change that to 270. 270=Top 90=bottom 0=right 180=left and so on, the 500 is just distance from center.

    So what your looking for would be to change the 55 to 270 and 500 to say 300.

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    OMG!!!

    Thanks a million @BBEnk‌! I feel so dumb right now! It's working great now! Thanks again. I just needed to put the 270 in.

    Thanks again!!! Can't thank you enough!!!

  • BBEnkBBEnk Member Posts: 1,764

    Your Welcome.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Yes remember in layers things fire from bottom to top. Not top down as in actors. As soon as I saw what you wrote about jitter i kne it was a layer issue before I scrolled down to see you sorted it. Many times we overlook layer order.

Sign In or Register to comment.