Boomerang Effect

poehyrulian

  • Posts: 78
basically brand new to stencil and have a miniscule amount of programming knowledge. right now im making a fan based Zelda game with link as the main character. wondering how to make a boomerang that comes back to link after it hits something or goes out of screen bounds. please help im screwin up

JeffreyDriver

  • Posts: 2262
Depending on how realistic you want this to be, it could be quite complex to achieve (for example if you want it to arc.) If you want it to just travel in straight lines though, it's pretty easy. A basic approach would be to have it simply change direction/velocity so that it heads back to the player. You could use a boolean that switches when it hits an enemy or goes out of bounds, or you could fake it entirely and kill the boomerang when it hits and enemy and create a new one that goes back to the player.

poehyrulian

  • Posts: 78
its proven to be not so simple ive spent the last few hours trying many combinations including the ones you have described. but have noticed that I only get bugs if I use my actor attribute for link. should I have it set to something other than actor
?


poehyrulian

  • Posts: 78
sorry it took so long but I figured it out thanks to some videos about enemy ai... the code reads
boomerang event.
<<when [self] is [created].
((((do after [1.5] seconds.
((do every
  • seconds.

{set velocity to  dir: [[[atan2 (y:[[ yposition ]- [y of self]] x: [[xposition]-[x of self]]] as [degrees] degrees, speed: [20] for [self]}
(if <<[yposition] = [[y] of [self]> and <<[xposition] = [
  • of [ self]>>
[kill [self]]))))))
>>

then ive set the xposition and yposition attributes to constantly be links position
{when updating.
( set xposition to [
  • of [self])

( set yposition to [[y] of [self])
}


poehyrulian

  • Posts: 78
Sorry if its hard to understand I tried making look as close to code as possible. Any way hope others find this useful

poehyrulian

  • Posts: 78
BTW now I'm on the new issue of creating a power atk with the boomerang. When I hit action1 the loop begins. What I want is if control 1 is held the boomerang instead gets four way movement for as long as control one is held... My problem is that when that when it is released the loop doesn't continue to flow. Any idea how I'd make that happen?