camera rotation, stationary actors and hud, please help.

Hi guys, I've looked all over the forums and google for an answer before asking here, so hoping someone can help.

what i want to achieve is:

actor and hud items stay stationary while the camera is rotated,

my scenes are around 2000 x 2000 and I'm already using the one big actor placed at the centre of a none scrolling layer, constrained to camera rotation thus achieving my desired effect on a background image.

but now what i need now is multiple actors that don't move around with the scene when the camera is "freely rotated"

its driving me mad! haha :)

I've seen the rolling bones game in motion and played it but can't find a template for it! i see that does something similar for hud actors, although I'm unsure if its using the one big actor method?

I've tried making a "dummy actor" thats constrained to the centre of my scene and have some game attributes hold x y data for this. using this i can place actors where i want but the still move around the dummy actors centre.

any help would be great guys, thanks

Jay

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    You need to constrain the HUD actors to . . .

    X position to (radius from centre) *cos (- camera.rotation+angle offset) +Xcentre
    Y position to (radius from centre) *sin (- camera.rotation+angle offset) +Ycentre
    Rotation to -camera.rotation

    If you need these actors to be interactive (i.e. buttons) rather than just display, then there are a couple of other things that need to be taken into account that I won't go into here.

  • jay2dxjay2dx Member Posts: 611

    @socks thanks for the help, this is great man, I'll try it out in the morning :) from your text I rekken I'll be on the right path, they are mainly for tutorial items etc, I've cheated with some by using display text on the background actor! :) but it's not enough, I need graphics etc, plus I've a few games I need to do this in.

    My next challenge once I figure this out will be making one actor interactive and constraining to the players input but snapping back to the centre when touch is released,

    Wish me luck, or should I say logic :) have a great weekend

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @jay2dx said:
    @socks thanks for the help, this is great man, I'll try it out in the morning

    A very quick example project attached below:

    @jay2dx said:
    My next challenge once I figure this out will be making one actor interactive

    This is where it gets weird ! :) :D You will need to make a second actor that doesn't rotate with the camera (so is out of sync with the first actor) because the first actor will not register a touch . . . but the second actor will register a touch even though it's flying around the screen and nowhere near where your finger is touching the screen . . . . that's not a great explanation, it's better to just say that things get weird, let me know if you get the first part working.

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @jay2dx said:
    My next challenge once I figure this out will be making one actor interactive . . .

    Ok, a new example project attached below:

    This is an example of what I mean by the touch/'image' sync issue with spinning cameras.

    The orange square is the HUD element, it will stay locked to the screen, but if you give it a touch behaviour (for example play a 'beep' sound when touched) it won't work, because the actor may be locked to the screen, but its touch position goes with the camera.

    So you need to make a second actor (the yellow square) that is not constrained to stay locked to the screen, this actor can contain our touch behaviour - now when you touch the orange actor, the yellow actor will play the 'beep' sound . . . because the yellow actor's touch position is not actually moving . . . (!) . . . honestly ! :)

    So, the orange actor's 'image' stays locked to the screen while its touch position stays with the camera's rotation.

    And the yellow actor's 'image' stays with the camera's rotation, while its touch position stays locked to the screen.

    Not very intuitive, but once you get used to it, it all kind of makes sense . . . hope that makes sense !

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    Just had a thought, there's no real need to calculate the radius or the angle offset, you can just have GS calculate them for you, so you'd just need to drag the actor to where you need it and then it will stick there . . .

    You'd create two local attributes for the actor, one for radius and one for angle, in this example I'm using a 1024 x 768 iPad project.

    So . . . .

    Change self.radius to magnitude(self.x - 512, self.y - 384)
    Change self.angle to vectorToAngle(self.x - 512, self.y - 384)
    Constrain self.x to self.radius *cos(- scene.Camera.Rotation + self.angle)+512
    Constrain self.y to self.radius *sin(- scene.Camera.Rotation + self.angle)+384
    Constrain self.rotation to -camera.rotation

    . . . hold on I'll test it out . . .

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

    Here you go, project attached, now you can simply drag your HUD elements into position when you are designing the scene and all the trigonometry is calculated for you.

  • jay2dxjay2dx Member Posts: 611

    Wow man thanks so much :) just about to sit down and try all this! :) can't thank you enough, if you ever need some game art in return for your help please let me know! Now time to get game making :)

    Thanks again will let you know how I get on

  • jay2dxjay2dx Member Posts: 611
    edited August 2016

    @socks this is amazing i can't thank you enough :)

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

    @jay2dx said:
    @socks this is amazing i can't thank you enough :)

    Glad it's working for you.

    A quick point, make sure your HUD elements are always above the camera controls (in the layer order), the HUD elements are looking at the camera for their position so the camera's position needs to be resolved before the HUD elements can work out where they need to be.

    . . . . . . . . .

    Good !

    HUD
    stuff
    stuff
    background
    Camera controller

    . . . . . . . . .

    Bad !

    Camera controller
    HUD
    stuff
    stuff
    background

    . . . . . . . . .

  • jay2dxjay2dx Member Posts: 611

    its working great thank you @Socks your help has been so good, on my list next is to enable the same hud actor to be constrained to the players finger input on the X axis and snap back to the centre when touch is not true!

    I've had a play around with this today, not got it to work correctly just yet but its fun trying :) i have a few ideas but can't do any more work until Tuesday evening now, real job starts tomorrow lol

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @jay2dx said:
    . . . on my list next is to enable the same hud actor to be constrained to the players finger input on the X axis and snap back to the centre when touch is not true!

    Hmmmmm . . . like I say the logic gets a bit weird because the touch position and the actor's image on screen are separated by the moving camera (I wouldn't call this a bug, but it would be great if this didn't happen) . . . so just bear in mind that you are getting the 'touch' actor (the one flying around the scene) to move along the X axis rather than the actor you are touching (the static image) . . so with that in mind the code should be something like . . .

    For the touch actor you'd use a simple when touch is pressed constrain to mouse X (even though the actor is spinning around the screen) - basically treat this actor as if it is static, ignore what it appears to be doing on screen.

    For the 'image' actor you'd need to constrain its X, Y and R to . . .
    (I'm using iPad 1024 x 768 as an example size again, hence the 512 and 384s)

    X = (magnitude(touch X-512, touch Y-384)) * cos(-camera rotation+(vectorToAngle( touch X -512, touch Y-384)))+512

    Y = (magnitude(touch X-512, touch Y-384)) * sin(-camera rotation+(vectorToAngle( touch X -512, touch Y-384)))+384

    R = -camera rotation

    Note: Once you've done the equation for X you can cut and paste it into the Y constrain and then simply change the cos to sin and the 512 at the end to 384.

  • jay2dxjay2dx Member Posts: 611

    That's great thanks @socks well the touch actor is only a visual reference and used to show the user how to control the gameplay, currently I have no visual guides so users are confused how to play until I show em, "I wish I could show you the game but I fear it will be copied so waiting until it's done for a reveal!" But I have everything working control wise using, as you say, the actors that spin around etc, so yeah I just need a point of reference to show the user where to place their finger when they want to manipulate the scene. This is my problem as I want to constrain it to the centre, which now works thanks to you, and then have it move with the users touch input along the X axis and snap back to the centre when touch is not true. You've put me on the right path :)

    Thanks for the head start with all this your help is really appreciated :)

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

    @jay2dx said:
    This is my problem as I want to constrain it to the centre, which now works thanks to you, and then have it move with the users touch input along the X axis and snap back to the centre when touch is not true. You've put me on the right path :)

    Here's a quick demo (attached), should help you get the general idea:

  • jay2dxjay2dx Member Posts: 611

    Nice one @socks :) genuine good fellow you sir

  • jay2dxjay2dx Member Posts: 611

    @socks got it all working how I want it to thank you so much

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

    @jay2dx said:
    @socks got it all working how I want it to thank you so much

    Glad it works for you !

Sign In or Register to comment.