Making actor go back and forth.

LogoLogicLogoLogic Member Posts: 51
edited November -1 in Working with GS (Mac)
I am trying to get an actor to go back and forth across the screen so he does not disappear and reappear on the other side. I tried the pacing tutorial but the actor is still going off the screen and reappearing on the other side.
Thanks!

Comments

  • TwilightHunterTwilightHunter Member Posts: 146
    Here I am again! Sup?... hehe.. Anyway, What I do for things like pacing is this:
    Pacing Actor, and two Bumpers.
    Make one bumper for the left of the screen. And one bumper for the right side of the screen, and on these make sure "Movable" is unchecked in the physics tab of the actor. Inside Pacing Actor:
    Rule: When Pacing Actor Collides with Bumper Right Side, (I use move alot of the time so that I know it will work) Move Left (180 degrees whatever) at Speed of 100 (change to your liking)
    When Pacing Actor Collides with Bumper Left side, do the opposite, move Right(0 degrees) at speed of 100. and he'll repeat it himself. You can use the same bumpers for all of the obstacle characters in your game.
  • TwilightHunterTwilightHunter Member Posts: 146
    And make the bumper invisible ;P
  • LogoLogicLogoLogic Member Posts: 51
    Is there a way to not have another object like a bumper? I would like the actor to just change directions when he reaches the edge of the screen.
    I am playing around with the timer and velocity right now. I can get him to move straight across the screen but he disappears and reappears.
    Thanks TH.
  • LogoLogicLogoLogic Member Posts: 51
    Lol.
  • POMPOM Member Posts: 2,599
    to make an actor go back and forth you can do:

    constrain attribute : self X to sin( self.Time * "speed" ) * pixels to move + starting positionX

    speed - any integer
    pixels to move - any integer - for example if you put 30 the actor will go 30 to the right and 30 to the left , so the total movement will be 60 pixels wide.
    starting positionX - the initial X value of the actor in the scene (do not use self.x)

    play with the numbers till you rich your result.
    hope it hepls
  • LogoLogicLogoLogic Member Posts: 51
    p-o-m, so would not use another actor as TwilightHunter suggested?
    I will play around with both ways. Thank you.
  • TwilightHunterTwilightHunter Member Posts: 146
    Uhh... I'm pretty sure just use:
    Change Velocity to 200 (To set initial speed)
    {
    Every 3 Seconds (Change)
    Change Attribute:
    Self.Motion.LinearVelocity.X to -Self.Motion.LinearVelocity.X
    }
  • POMPOM Member Posts: 2,599
    both ways will work ! , TwilightHunter's way is with behaviors, and the way i mentioned is using
    math, your choice !

    p.s , the way i mentioned dont required another actors,
    just the constrain rule above in the moving actor.
    good luck =)
  • LogoLogicLogoLogic Member Posts: 51
    Being not so good with math I am going to try TwilightHunters first.
    I tried to follow you p-o-m and my head started hurting :)
    Thanks.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    I did this a long time ago, so the names might have changed since then

    In my actor I created a variabl called direction. I have a timer that says every X seconds (1 in my case ), change that attribute to (actor.Direction+1)%2. This switches the value from 0 to 1 and back every second

    I the created two rules, go left and go right and just told them if direction is 1 move right. If direction is 0 move left you just need to adjust the timer to fit your screen nworked much better for me than the sin funcon

    Sorry for typos, I'm on my iphone
  • LogoLogicLogoLogic Member Posts: 51
    Twilight, I made the bumpers and set them but my actor is going right through them. What did I do wrong?
    I will keep playing around with it.
  • LogoLogicLogoLogic Member Posts: 51
  • jweaver911jweaver911 Member Posts: 439
    if you want to save the processing power and not use constraints or extra actors....

    Just make a rule that says when self position less than or equal to some x value change direction. I have that rule in effect to keep my guy within a certain "boundary" and that seems to work really well.

    Note you have to use the opposite value for the other end(right side of the screen: greater than or equal to).

    IE.

    RULE

    Move left, speed 200 direction relative to actor
    When self position <or= 5 move right, speed 200, direction relative to actor
    When self position >or= 475 move left etc..

    NOTE: >or< symbols(and not simply equals alone) will ensure that if GS stutters and misses your actor at the specified pixel value it will still trip the rule.
  • LogoLogicLogoLogic Member Posts: 51
    I will play around with that. I would like to post up a screenshot but I cannot seem to get one through on GS. Do they block screenshots?
  • LogoLogicLogoLogic Member Posts: 51
    jweaver911:
    I did this

    http://img268.imageshack.us/img268/295/screenshot20100708at815.png

    and the actor just moves continuously to the right and comes across the screen and keeps going that way. Can you help?

    Thank you.
Sign In or Register to comment.