How to make a spawn actor go to the mouse click position
Guys iam making a game where the may actor, can fire and spawn ˜bullet actor˜, but steady of making these actors only respawn and go to a specified direction, i want to make the bullet to move to the place where i have clicked with the mouse, how can i do that?
Best Answer
-
jckmcgraw Posts: 647
There's a video on the GameSaladCookbook's youtube channel that TSB made that should help.
EDIT: TSB beat me to it!
Answers
1. make 2 Real game.attributes
2. call them BulletX and BulletY
3. into MainActor, make a Rule that says that when mouse button is down, it spawn a BulletActor
4. add 2 Change Attribute behaviors, one changes BulletX to Mouse.Position.X, the other one changes BulletY to Mouse.Position.Y
5. go into BulletActor and do this:
interpolate behavior -> Bullet.Position.X to game.BulleyX, (set its duration as you want, 0.5, 0.2, whatever)
another Interpolate -> Bullet.Position.Y to game.BulletY, (set its duration as you want, 0.5, 0.2, whatever)
so, wherever you'll tap your finger on the screen, your BulletActor(s) will move to that position.