GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Left and right

rubber-chickenrubber-chicken Posts: 12Member
edited 11:31PM in Working with GS (Mac)
Hi

I have an actor which is the player, he is facing right and shoots to the right. How do I get him to face left when the left key is pressed and shoot to the left also??

Comments

  • CodeMonkeyCodeMonkey Posts: 1,803Head Chef, Member, PRO
    First you need images with your player facing the other direction.

    Use that with a Change Image behavior when you press the left key.

    Create an actor attribute that you set to know when you are facing left or right. Then use that attribute when you look for the key to shoot and have different spawn behaviors depending on which way you face(the attribute)
  • quantumsheepquantumsheep Posts: 8,188Member
    Heh - that's probably the most efficient way of doing it :)

    I managed to get the same thing done with two actors - one for left, one for right - that destroyed eachother and spawned the other actor when the key was pressed.

    So if the Right facing actor has the left key pressed, it destroys itself and spawns a left facing actor etc etc.

    This does, of course, mean you have to double up your rules for each actor, with minor tweaks (like shooting in a certain direction etc)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: http://www.quantum-sheep.com

  • jetsetcrashjetsetcrash Posts: 17Member
    what kind of attribute would this be I don't completely understand this. Using an integer attribute

    left arrow down constrains attribute to 1
    right arrow constrains to 0
    1 moves 180 from actor
    0 moves 0 from actor works but if you switch left and right the spawned actor switches midflight, how do i alleviate this. Also my main actor has drift and accelerate for move so he continuous to drift in a direction after releasing direction arrow how do i get him to continue to shoot in that direction if the key is released? Is there a way to make an attribute know what image the actor is?

    i might have to try that spawning technique, should work with drag, no?
  • scitunesscitunes Posts: 4,047Member, Sous Chef
    use boolean

    when right key is down

    CHANGE attribute facingright = true(1)
    move (or accelerate) 0degrees
    change image to guy facing right

    when left key is down

    change attribute facingright = false (0)
    move 180degrees
    change image to guy facing left

    now for the shooting

    when shoot button is down
    AND facingright is true

    spawn bullet actor (angle = 0)

    when shoot button is down
    AND facingright is false

    spawn bullet actor (angle = 180)

    in the bullet use a move or velocity or accelerate behavior (experiment until it works to your liking) Don't set the angle of motion in the bullet (leave at 0 relative to actor) The angle gets set in the shooter actor that is spawning the bullet.
  • jetsetcrashjetsetcrash Posts: 17Member
    thanks!
This discussion has been closed.