Shooting an actor at another actor

daniel.robert.campbelldaniel.robert.campbell Member Posts: 251
edited November -1 in Working with GS (Mac)
It's time for Daniel's "Super Noob Question of the Day!"

I am having trouble. I have a set of crosshairs, I have a ball at the top of the screen. I have the crosshairs tracking the mouse.

When the mouse button is pressed, I want the ball to be launched at the crosshairs. I have no idea how to do this. Please help?

Comments

  • ORBZORBZ Member Posts: 1,304
    create two game attributes:

    crosshairX (real)
    crosshairY (real)

    inside your crosshair actor do this:

    constraint game.crosshairX = self.position.x
    constrain game.crosshairY = self.position.y

    in the ball actor:

    on mouse down
    change velocity angle: vectorToAngle(game.crosshairX - self.position.x, game.crosshairY - self.position.y) speed: 300
  • Awesome. Thank you very much.

    So...when you say "constraint" on the crosshairs, you mean "constrain attribute" right?

    I went ahead and did that along with the behaviors to get the crosshairs to follow the mouse. Now when I preview, the crosshairs are not visible at all. :-(

    Again, thanks a ton for the help.
  • Help! I'm stupid! Sorry about that. I took a closer look and found my mistake.

    Thanks for the help. I owe you a big nasty Dan hug. ;-)
  • I don't suppose there is any way to get this to work with the accelerate behavior. I'd love the ball to have gravity to it. Sorry to be such a pain.
  • Alright, so now my big problem is there there is no gravity on the ball. I still want the ball to be launched towards the crosshairs, but also be pulled down by some gravity.
  • ORBZORBZ Member Posts: 1,304
    accelerate towards your target as stated before, but simultaneously add another accelerate behavior that accelerates 270 degrees (scene down)
  • Thanks ORBZ. You = awesome.
  • Its strange. They gravity on the ball was working fine for a long while. But GameSalad crashed and after rebooting it seems to have screwed up the gravity. I'm going to do a little more digging to see if I managed to screw something up...but I'm fairly sure I didn't :-(.

    Is there any kind of known bugs about this kind of thing?
  • Alright, so I made a new project and did everything just like described above...now I can't get my ball to have gravity after it is launched. Can anyone please help? Pretty please?
  • Yes. Thank you tshirtbooth.

    We ended up fixing it by using timers. we put a timer of 0.1 seconds on the "vector to angle" attribute. And another time of 0.2 (this one was run to completion) for the accelerate down behavior.
  • lol. And a sprinkle of pure awesome. :-)
Sign In or Register to comment.