Rotating actor in game

joelloydjoelloyd Member, PRO Posts: 119

Anyone ever made an actor that can be rotated on the spot by the player? I'm after achieving this. Thank you for any answers

Comments

  • bjandthekatzbjandthekatz Orlando, FlMember Posts: 1,375

    What do you mean rotated by the player? How do you want it to be controlled?

  • joelloydjoelloyd Member, PRO Posts: 119

    So imagine you place a rectangle actor in a scene, I want the player to be able to rotate the position of it. it won't move relevant to the scene, just rotate. For instance, almost like when you in gamesalad can rotate an actor when making the game. Thanks

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

    @joelloyd said:
    So imagine you place a rectangle actor in a scene, I want the player to be able to rotate the position of it. it won't move relevant to the scene, just rotate. For instance, almost like when you in gamesalad can rotate an actor when making the game. Thanks

    When touch it pressed:

    Constrain Rotation to vectorToAngle (game.Mouse.Position.X - self.Position.X , game.Mouse.Position.Y - self.Position.Y)

    (this works with a plain coloured actor, but if you include an image then you'd need to introduce an angular offset).

  • joelloydjoelloyd Member, PRO Posts: 119

    Thanks socks, looks like I'll make it a plain colour then, but for future purposes. Never applied an angular offset, is this easy? Thanks a lot

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2015

    @joelloyd said:
    Thanks socks, looks like I'll make it a plain colour then, but for future purposes. Never applied an angular offset, is this easy? Thanks a lot

    It's not complex at all, just some basic adding and subtracting of angles, you basically want the actor to know what its current rotation is and then when you rotate the actor it rotates itself relative to that current rotation, rather than simply relative to where the mouse is . .

    So it should work something like this:

    . . . . . . . .

    Make a 'real' attribute in the actor, let's call it 'OffSet'.

    Rule: When touched is pressed:

    Change Attribute 'Offset' to:
    vectorToAngle (mouse.X-self.X, mouseY-self.Y)-self.Rotation

    Constrain Attribute Self.Rotation to:
    vectorToAngle (mouse.X-self.X, mouseY-self.Y)-Offset

    . . . . . . . .

    Might need to check that's all right when I get the chance, but I'm pretty sure that'll work just fine.

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

    Here you go, I've made you a quick demo project (attached) it works fine:

Sign In or Register to comment.