Rotating actor not working as expected I need of some help

JorrowJorrow Member Posts: 6
edited March 2015 in Community Tutorials

My actor starts at 41° I would like it to move to 340° when clicked then when clicked again return to 41°
I have done
if self.rotation=41 do rotate to angle 340
and
if self.rotation=340 do rotate to angle 41
It will rotate from 41° to 340° when clicked then when clicked again it goes back to 41°. But after that when clicked on again it wont move any more, I would like it to keep moving between 41° and 340° thanks

Comments

  • kolabokolabo Member Posts: 240

    Here's one way to do it:

    Make a new attribute for your actor (integer).
    Call it something like "stateRotation" and give it the value 1

    Then, make 2 rules for your actor:

    Rule 1) When all
    Actor receives event touch is pressed
    and Attribute "self.stateRotation" = 1

        Rotate to Angle 41 Relative to scene
        Check the run to completion and stops on destination boxes.
        and
        Change Attribute "self.stateRotation" to 2
    

    Rule 2) When all
    Actor receives event touch is pressed
    and Attribute "self.stateRotation" = 2

        Rotate to Angle 41 Relative to scene
        Check the run to completion and stops on destination boxes.
        and 
        Change Attribute "self.stateRotation" to 1
    
  • JorrowJorrow Member Posts: 6

    @kolabo said:
    Here's one way to do it:

    Make a new attribute for your actor (integer).
    Call it something like "stateRotation" and give it the value 1

    Then, make 2 rules for your actor:

    Rule 1) When all
    Actor receives event touch is pressed
    and Attribute "self.stateRotation" = 1

        Rotate to Angle 41 Relative to scene
        Check the run to completion and stops on destination boxes.
        and
        Change Attribute "self.stateRotation" to 2
    

    Rule 2) When all
    Actor receives event touch is pressed
    and Attribute "self.stateRotation" = 2

        Rotate to Angle 41 Relative to scene
        Check the run to completion and stops on destination boxes.
        and   
        Change Attribute "self.stateRotation" to 1
    

    Thanks for your help
    This didn't seem to work wouldn't rotate at all. Here is an image of rule incase I have done something wrong
    http://i.imgur.com/1qHwMeC.jpg

  • kolabokolabo Member Posts: 240
    edited March 2015

    Your first rule looks correct. I can't see all of the second rule in your image.

    Did you remember to manually set the attribute "stateRotation" to 1 ?
    By the way, in my first rule I should have typed Angle 340. My bad. I guess you caught that.

    It works for me, though I'm on a Mac. Don't think that should make a difference.
    Have you tried this on a new project?

    Edit: Change your first rule to rotate to Angle 340, and the second to 41.

  • JorrowJorrow Member Posts: 6

    @kolabo said:
    Your first rule looks correct. I can't see all of the second rule in your image.

    Did you remember to manually set the attribute "stateRotation" to 1 ?
    By the way, in my first rule I should have typed Angle 340. My bad. I guess you caught that.

    It works for me, though I'm on a Mac. Don't think that should make a difference.
    Have you tried this on a new project?

    Edit: Change your first rule to rotate to Angle 340, and the second to 41.

    Tried it on new project turned one way then not back
    here is the second rule http://i.imgur.com/vqo9Ba8.jpg

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

    When touch is pressed
    --change angular drag to 1-angular drag
    --Interpolate rotation to (angular drag *299)+41

  • kolabokolabo Member Posts: 240

    Looking at your rules again.
    Change your first rule to rotate to 340, and the second rule to 41.
    Let me know if that works.

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

    example:

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

    @Jorrow said:
    Tried it on new project turned one way then not back

    The problem is - when you press, the state changed to 2 - but you are still pressing - so you are now pressing with the state being 2, which triggers the second rule.

  • kolabokolabo Member Posts: 240

    @socks - That's a nice solution. I like the way you borrowed the angular drag attribute instead of making a new attribute.

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

    @kolabo said:
    socks - That's a nice solution. I like the way you borrowed the angular drag attribute instead of making a new attribute.

    Technically this is known as 'laziness'.

  • kolabokolabo Member Posts: 240
    edited March 2015

    Maybe it was laziness for you, but I took a double look before I caught what you were doing. Now I can be technically lazy too! :smiley:

    Edit: "technically be lazy" and not "be technically lazy".

  • JorrowJorrow Member Posts: 6
    edited March 2015

    @Socks said:

    This way works thanks for everyones help
    one more question not important but is there a way to change where it rotates from. Instead of rotating from the middle of the actor, It rotates around a point to the right of the center of the actor

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

    @Jorrow said:
    is there a way to change where it rotates from. Instead of rotating from the middle of the actor, It rotates around a point to the right of the center of the actor

    This is generally a shortcut to wasted time, keeping a detail like that hidden from people answering your question can often render their efforts a waste of time, for example ask someone how to do ABC, someone goes off and works out a little bit of code for you, you then add that once your project has done ABC it then needs to do XYZ, which might be impossible to do with the code that the person helping you has worked out - this happens a lot. If you'd told them in the first place that you need ABC and then XYZ they would have likely taken a different approach.

    Offset rotation involves a little trigonometry (unless you are @RThurman, in which case you can use magic) so you'd need to take a different approach, but you could use the numbers generated by the above code as the angle for cos and sin to operate on, example attached.

    @Jorrow said:
    edit I know i'm a pain but is there any way I can make it rotate the other way when going back eg clockwise to 340 then anticlockwise to 41

    Again, I'd make the same point, code cannot be easily adapted to whatever we want once it's been built, usually you built it with a specific purpose in mind, so if I ask someone to build me a duck, that person goes off and works out how to build a duck, after showing me his duck I say 'that looks great, but could you make it a dog instead' - to me they might all be animals, but to the duck maker there might be two entirely different approaches ! :smile: Hope that makes sense.

    tl;dr - delivering information piecemeal (I want something to rotate between two angles - actually it needs to rotate from a non-central position - actually it needs to always rotate in the same direction) results in a lot of handwork redoing code.

  • JorrowJorrow Member Posts: 6

    @Socks said:
    tl;dr - delivering information piecemeal (I want something to rotate between two angles - actually it needs to rotate from a non-central position - actually it needs to always rotate in the same direction) results in a lot of handwork redoing code.

    Sorry this is my first project and i'm trying to work out what looks right as I go along.I don't think the pc version can open files from the mac version, It tells me it is for a newer version of gamesalad but I have the newest version

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

    @Socks said:
    Sorry this is my first project and i'm trying to work out what looks right as I go along.

    There's absolutely no need to apologise ! :) I just like a good rant ! lol :smiley:

    Let me take a screen shot of the code . . . .

    I used the image attached (arm.png), place it in GameSalad and apply it to a 298 x 123 pixel actor.

  • JorrowJorrow Member Posts: 6
    edited March 2015

    @Socks said:

    This doesn't work for me the actor disappears as soon as I start. But I have worked out a different way. Im just doing when touch pressed destroy and spawn new one in correct place doesn't look as good but it works
    But thanks for your help

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

    @Jorrow said:
    This doesn't work for me the actor disappears as soon as I start.

    Not surprising, the numbers in the above example where just guesses, I don't know whether you are using a portrait Android project or a FireTV project (or something else entirely), those numbers were for a landscape iPad, but anyhow sounds like you've got something working regardless, so I'd go with that.

Sign In or Register to comment.