Missile Question - Can a missile shoot towards where you touched the screen?

samdelgadosamdelgado Member Posts: 10
edited November -1 in Working with GS (Mac)
Hey everyone,

I am new around here and have just been fooling around with gamesalad to see what it can do. I have a basic idea of game I might try making, but I can't figure out how to create something. Essentially I want a game like the Space Rocks demo, but you move the ship with a virtual joystick with your left thumb and you shoot the missiles by tapping on the screen where you want it to go. So I still want the missiles to leave from the actor, but I want them to go to wherever my finger touched the screen. Is this possible? Thanks for your help in advance.

Comments

  • samdelgadosamdelgado Member Posts: 10
    Anyone? This is the only thing stopping me from trying it out. I have fooled around with the space rocks template a ton but can't seem to get the missile to shoot towards where the screen was touched.
  • samdelgadosamdelgado Member Posts: 10
    Wow thanks for the awesome reply! I will be trying all of this shortly and I'll let you know how it goes.
  • samdelgadosamdelgado Member Posts: 10
    Ok i have attempted this on both my own game and the space rocks game but cannot get a missile to actually fire. Am I doing something wrong with the mouse position part?I understand the logic behind everything and it seems like it should work, but the missiles just won't spawn. Were you successful with exactly this? Thanks a ton for the help its been really informative.
  • samdelgadosamdelgado Member Posts: 10
    By the way, this will be an ipad game so idk if that changes any of the attributes I need.
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    does your game scroll?
  • samdelgadosamdelgado Member Posts: 10
    Yeah its a big king of the hill type map. The screen moves around all over it. Right now I am just using random google images to see how it all will work, so I don't really have much. I will send you what I have done to the space rocks template and you can look at why I can't get it working there.
  • samdelgadosamdelgado Member Posts: 10
    Hey tshirtbooth,

    I got the email and of course it was a stupid as forgetting to actually drag the actor onto the screen. My game isn't much like space rocks one I was just using that to try to get the functionality down. Thanks a lot for helping me out!
  • samdelgadosamdelgado Member Posts: 10
    I guess the next question is how do I get the missile to face the direction it is going? I have tried making it so the direction is towards the game.x.mouse and game.y.mouse positions, but that just leads to no missile coming out. It seems like this should be a simple fix. Any suggestions?
  • samdelgadosamdelgado Member Posts: 10
    I see. In what I am wanting to create i would just be a circle that shoots like a fireball out of its sides. There would be no way to make the fireball animation shoot straight toward where the player touched the screen?
  • samdelgadosamdelgado Member Posts: 10
    Does anyone know how to accomplish what I am asking in my previous post?
  • PhoticsPhotics Member Posts: 4,172
    vectorToAngle( self.Position.X - touchX , self.Position.Y - touchY )
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Photics' post explains how you determine the angle at which to shoot.

    To get it to actually shoot, you would need to use that expression in a CHANGE VELOCITY or MOVE behavior.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Hi Guys. Im currently working on this and have a few questions. I am following what Tshirt has explained and that works great, however i would like the missile to carry on going. i.e. you touch on the screen, the actor spawns the missile, the missile heads to the touched location but then stops. Ideally, i would like it to carry on with the same path until it hits an enemy or goes off screen at which point it will be destroyed. Any ideas how to do this? Ta
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    try accelerate within a timer

    put the vectorToangle part in the direction
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Thanks SciTunes but i didnt need to do that, stupid me must be tired. i hadnt realised that photics actually said self.position, i was just automatically thinking it was self.x! D'oh. When i put what was said in change velocity it worked great.

    So this wrapped in change velocity did work ... as stated by barkbark00.

    vectorToAngle( game.touch x - self.Position.X , game.touch y - self.Position.Y )

    Note to myself * Re-read things ... several times!
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Just want to make an adaption to this and am a little stuck figuring the best way to do it ...

    Basically i want my actor to rotate and fire the missile where i touch. e.g. if he is straight and i touch in front of him he just fires the missile, if i touch diagonally right i want him to rotate diagonally left a bit so that he is again parallel to where he is shooting.

    I tried creating a rule that said if touch.x and touch.y is greater than self.position x and y then rotate to x but once i have the 4 scenarios in place and the main actor is moving quite a bit it doesnt detect it to well. Anyone got any ideas on this? Can it be done with some math?
  • jmp909jmp909 Member Posts: 73
    what happens when you touch a new area whilst the actor is already rotating? should he stop and rotate to the new area? or finish rotating to where he was going, fire, and then rotate to the new touch area?

    not that i can solve your problem, but specifying the whole action should help someone help you better
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    it wasnt triggering properly. what i would like is;

    imagine the actor is in the centre of the screen

    If you touch top right, he would rotate anti-clockwise 45 degrees and shoot straight to the top right corner

    If you touch bottom right he would need to rotate 45 degrees clockwise and shoot straight to bottom right.

    What i would like is it to override on new touch. i.e. If you're firing top left and then hit top right it switches straight away rather than wait for a sequence to complete.
    Same rules apply for the left hand side.

    Now i guess it would need to be rotate to angle and not just rotate as if you hit top left 1st and then top right you would end up in your original position as opposed to being rotated to the correct position to fire straight.
  • jmp909jmp909 Member Posts: 73
    i imagine vectorToAngle would solve this? I've not tried it but presumably something like vectorToAngle(newX-oldX, newY-oldY)

    from the Wiki:
    http://gamesalad.com/wiki/interface_reference:expression_editor

    vectorToAngle

    Usage: vectorToAngle(x,y)

    Find the angle relative to the origin, (0,0), given an X and Y coordinate. You can include an offset,(x',y'), to find an angle relative to the offset.

    e.g. vectorToAngle(x-x',y-y')
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Ok i'll give that a try. So what would the co-ordiantes of newX and y and oldX and y be? Do i need to be constraining my characters movements to this? Thanks for your help
Sign In or Register to comment.