How to make slice act like a boomerang?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

How to make slice act like a boomerang?

Post by sheamkennedy »

I've dealt with making projectiles but now want to make a boomerang. The projectile must first have a velocity going away from the player, then a return velocity coming back.

Is there an easy way for me to code something that checks what the current slice velocity is, then reverse it's velocity? My boomerang slice is already parented to my hero so no matter where I move I know the boomerang will always return to me, so that part is taken care of.

I noticed "get slice velocity x (handle)..." in the dictionary but it does not have a section that describes how it works really. I'll play around with that for the time being but please respond if you can think of an easy way to carry this out.

EDIT: As a first attempt I made a timer, once the timer is up the velocity is supposed to switch directions. These are the functions I used. It compiled but there seems to be no velocity in the opposite direction seen.

Code: Select all

      #This is meant to get the original velocity, then set the new velocity of the
      #slice so it is negative (in the opposite direction...
      set slice velocity x (Boomerang, (0 -- get slice velocity x(Boomerang)), 10)
      set slice velocity y (Boomerang, (0 -- get slice velocity y(Boomerang)), 10)
EDIT 2: I was able to work around this and make a working boomerang. My way unfortunately handles 4 variables (up, down, left, right) then sets the velocity to what I know to be the opposite velocity. This is not done mathematically as I originally wanted. Even though my thing works, it would be way less convoluted if someone could solve what I was originally trying to do.
Last edited by sheamkennedy on Sat Mar 07, 2015 2:02 am, edited 3 times in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

SliceVelocity is a value of pixels per tick.

Negative values are going left in the X dimension, or up in the Y. Likewise, positive values are going right in the X Dimension, or down in the Y. Thus, a slice with an XVelocity of -4 and a YVelocity of 4 is going South-West.

Your script should use the Sign command to determine whether or not the value is positive or negative to figure out how to reverse it.


The Absolute Value command will also be pretty useful for reversing the negative numbers. Your 0 -- Whatever is gonna work fine for turning positive values to negative.

Does it work if you face a different direction? I can't imagine it's not doing anything.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

No, I still can't get it to work that way. In game it shows my boomerang fly away from the player at it's original velocity, then it stops and the slice is freed. There is no return velocity for some reason.

I just attempted this since I figured it was a better mathematical expression than my original code (did not work unfortunately):

Code: Select all

      set slice velocity x (Boomerang, ((-1)*get slice velocity x(Boomerang)), 10)
      set slice velocity y (Boomerang, ((-1)*get slice velocity y(Boomerang)), 10)
And my code does not seem to behave differently while facing different directions.

EDIT: Also attempted the sign thing like you said, but to no avail (seems to show the same effect, with no return velocity):

Code: Select all

      
      set slice velocity x (Boomerang, (sign (get slice velocity x(Boomerang))* get slice velocity x(Boomerang)), 10)
      set slice velocity y (Boomerang, (sign (get slice velocity x(Boomerang))*get slice velocity y(Boomerang)), 10)
Last edited by sheamkennedy on Sat Mar 07, 2015 2:25 am, edited 4 times in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Stops and the slice is freed? That's curious. What part of the code frees the slice?
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Ahh, I may have discovered the problem. I added:

Code: Select all

show value (get slice velocity x(Boomerang))
And it displayed zero on my screen. Thus the slice is perhaps coming to the end of its journey and stopping somehow right as the reversal expression is called... Not sure how to fix this. I may have to think on it or go with the bulkier code I had working...
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Sorry I should show all the code, it may be a bit convoluted and hard to understand some of the other stuff going on but here it is:

Code: Select all

script, Boomerang Timer, begin
  #If the boomerang was just shot, a timer which changes phase of the boomerang begins, once the time
  #is up this script will retrigger causing the boomerang to switch phases and allowing the
  #player to shoot a new boomerang
  If (BoomerangWasJustShot == 1) then(
    BoomerangWasJustShot := 0
    boomerangPhase := 0
    set timer(11, 0, 11, @Boomerang Timer)    
  ) else (
    if (boomerangPhase == 0) then(
#      #Switch Phase
#      if(boomerangRight >> 0) then(
#        set slice velocity x (Boomerang, -15, 10)
#        boomerangRight := 0
#      )  
#      if(boomerangLeft >> 0) then(
#        set slice velocity x (Boomerang, 15, 10)
#        boomerangLeft := 0
#      )
#      if(boomerangUp >> 0) then(
#        set slice velocity y (Boomerang, 15, 10)
#        boomerangUp := 0
#      )  
#      if(boomerangDown >> 0) then(
#        set slice velocity y (Boomerang, -15, 10)
#        boomerangDown := 0
#      )  

      show value (get slice velocity x(Boomerang))
      set slice velocity x (Boomerang, (sign (get slice velocity x(Boomerang))* get slice velocity x(Boomerang)), 10)
      set slice velocity y (Boomerang, (sign (get slice velocity x(Boomerang))*get slice velocity y(Boomerang)), 10)
      set timer(11, 0, 11, @Boomerang Timer) 
      boomerangPhase := 1
    ) else (
      free slice (Boomerang)
      isBoomeranging := 0
      BoomerangWasJustShot := 1 
      boomerangPhase := 0
    )  
  )
end 
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Gizmog
Metal King Slime
Posts: 2622
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Beats the hell out of me!
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Gizmog wrote:Beats the hell out of me!
Haha. Well if worse comes to worse then I have that other code with all the variables. I'll play around with this some more.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

I figured it out! So basically my timer script was set to reverse the direction of the boomerang after 11 ticks had passed, but my "set velocity function" was set to last only 10 ticks. Thus the boomerang actually was at a velocity of zero during it's climax, so the mathematical function was just returning zero since there was no sign to change. It's very understandable that you couldn't solve this mystery because my set velocity function was set in my on-key press script which I hadn't shown you.
Last edited by sheamkennedy on Sat Mar 07, 2015 4:10 am, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

The code you posted in your first post is correct. No need to use 'sign'. The way you're using sign in that last script is quite wrong. Also, you wrote "get slice velocity x" instead of "get slice velocity y"
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

TMC wrote:The code you posted in your first post is correct. No need to use 'sign'. The way you're using sign in that last script is quite wrong. Also, you wrote "get slice velocity x" instead of "get slice velocity y"
Yeah I got it all working now. I did notice that x that had to be replaced with y earlier too when the game didn't seem to be doing what I wanted.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Here's a video showing how it turned out:
https://www.youtube.com/watch?v=QpWtO9G ... hH6wejO_Rr
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Post Reply