GameSalad

How to make slice effect for both vertical and horizontal directions?

teklrncogteklrncog Posts: 2Member, PRO
edited October 26 in Working with GS (Mac)

Hi everyone,

I am seeking to make a slice effect that if I use a blade to slice the rectangular twice (one vertically and one horizontally), the rectangular will be separated into 4 pieces (figure.1).

But when I tried to program it, it didn't work. It worked perfectly for slicing either horizontally or vertically, but when I tried to do both consecutively, it always had a problem. Sometimes the second slicing could not be proceeded; sometimes the rectangle was cut into 6 pieces (the big rectangle was made of 6 smaller ones)...most weirdly it depended on how fast I sliced... I think the problem is that the code wasn't able to detect if it's a horizontal or vertical slicing effectively so there was always a bug...

Here's how I tried to detect the orientation of the slicing/blade (behavior in the blade):

If blade collides with rectangle and abs(self.Motion.Linear Velocity.Y) >= abs(self.Motion.Linear Velocity.X)
    Change attribute game.blade_vertical to true
    Timer after 1 second Change game.blade_vertical to false
Otherwise
    If blade collides with rectangle and abs(self.Motion.Linear Velocity.Y) <= abs(self.Motion.Linear Velocity.X)
        Change attribute game.blade_horizontal to true
        Timer after 1 second Change game.blade_horizontal to false

This has a problem that GS only recognizes ">="/"<="... if I put ">"/"<" the blade never worked...but if I put ">=" for the first one, the second condition never got activated...

Does anyone have an idea how I can improve or change my code to let GS detect the orientation of the blade correctly?

Thanks a lot in advance!

Comments

  • tatiangtatiang Posts: 11,027Member, Sous Chef, PRO, Senior Sous-Chef

    Just a note that option+space when posting here will add leading spaces (e.g. for indenting text). I edited your post above to add them to the rules you listed.

    I would recommend using a Display Text behavior to watch the values of your expressions such as abs(self.Motion.Linear Velocity.Y) and abs(self.Motion.Linear Velocity.X) to see if they equal what you think they should when slicing vertically or horizontally.

    The ≤, <, >, and ≥ conditions work fine in GameSalad... so there's something else going on with your logic.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • teklrncogteklrncog Posts: 2Member, PRO
    edited November 6

    @tatiang said:
    Just a note that option+space when posting here will add leading spaces (e.g. for indenting text). I edited your post above to add them to the rules you listed.

    I would recommend using a Display Text behavior to watch the values of your expressions such as abs(self.Motion.Linear Velocity.Y) and abs(self.Motion.Linear Velocity.X) to see if they equal what you think they should when slicing vertically or horizontally.

    The ≤, <, >, and ≥ conditions work fine in GameSalad... so there's something else going on with your logic.

    Thank you so much Tatiang! When I display the two linear velocities they are both 0....
    I wonder if it's because my actor didn't have a velocity per se as I constrained its movement to my touch movement (this object is a blade that players can drag around)? .... Do you have any advice how to detect a velocity in that type of movement?

  • tatiangtatiang Posts: 11,027Member, Sous Chef, PRO, Senior Sous-Chef

    Right, if you're constraining an actor's movement then it won't have any velocity in the physics engine. Have you checked out tutorials for detecting swipes? It sounds like you're using an actor's movement to determine the slices but if the player is swiping on the screen then you'd want to use a traditional method to determine that.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.