Random and fixed rotations

rjh5000rjh5000 Member Posts: 22
edited November -1 in Working with GS (Mac)
I'm making a game with a spinner for one element of it, the best way to describe it is like the spinner used in twister.

I'm made the spinner, depending on other elements in the game I need it to move by a fixed amount or by a random amount.

I have coded something similar before but this is my first attempt at using game salad, so not quite sure how it all works yet.

Here is what I am trying to do for the random rotation

//initial
spin=0;

//on touch
spin=room_speed*(5+random(5));

//step
if spin>0{
spin-=1;
angle+=5;
}

I'm sure something like this will be possible in game salad, but where do I do it? Is there somewhere to enter custom code? I'm a bit confused by the one line given for making functions.

Any help or pointers would be great.

Thanks

Comments

  • rjh5000rjh5000 Member Posts: 22
    Kind of got something working, but it only spins on press then stops when released, which isn't really random
  • DrGlickertDrGlickert Member Posts: 1,135
    I'd use a rule with a game.attribute (or self.attribute).

    Not sure what trigger you have established to make it spin a fixed amount or a random amount but if you only have one spinner then you could use a game.attribute (integer type).

    So the rule would be;
    If touch is pressed & Inside & game.SpinType = 1
    Then spin random
    Change attribute game.SpinType to 0
    OTHERWISE
    NEW RULE
    If touch is pressed & Inside & game.SpinType = 2
    Then spin fixed amount
    Change attribute game.SpinType to 0

    That's how I would do it. You'll have to set up a 'trigger' that will change the attribute of game.SpinType to 1 or 2 based on what your trigger is in your game.

    Hope that makes sense and helps you out.
  • rjh5000rjh5000 Member Posts: 22
    thanks for the reply,

    Yes I have done what you have said, scarily exactly like you said.

    The problem I am having is with the rule that makes the actor spin.

    I'm got this far now

    Rule

    Touch - release

    sub rule
    timer - random number
    rotate - speed

    This works, but at a fixed speed but it is random, it would be nice to make it slow gradually

    As for the fixed motion, I want to do something like

    Angle = Angle + 360/x
  • rjh5000rjh5000 Member Posts: 22
    rjh5000 said:
    thanks for the reply,

    Yes I have done what you have said, scarily exactly like you said.

    The problem I am having is with the rule that makes the actor spin.

    I'm got this far now

    Rule

    Touch - release

    sub rule
    timer - random number
    rotate - speed

    This works, but at a fixed speed but it is random, it would be nice to make it slow gradually

    EDIT:
    Done the fixed motion one now

    As for the fixed motion, I want to do something like

    Angle = Angle + 360/x

  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    I believe if you want in to slow down you just need to add angular drag and instead of setting a rotate behavior just do a single change attribute self.motion.angular velocity to the speed you want. that route a positive number will spin one way and a negative number will spin the other way. Then the angular drag you set in the actor should slow it down as it goes on. I haven't tested this so i'm not 100% positive.

    @DR GLICKERT. Please stop telling people to use touch is pressed and inside for their rules. its a waste of extra unneeded code and time. if you want to use it your self knock your self out but the is no reason to teach new users a wrong way of using those conditions.

    ___________________________________________________________________________________
    TEMPLATES AND PROJECT HELP BY TENRDRMER. CLICK HERE!!!

    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
  • rjh5000rjh5000 Member Posts: 22
    EDIT:
    That worked perfectly tenrdrmer, the effect works really well.

    For some actors the centre is slightly off set, is there an easy way to pick the point of rotation for different actors?

    Cheers for the tenrdrmer, will give that a go
Sign In or Register to comment.