How Do I make an actor stick with another actor ?

rishabgoyal1899rishabgoyal1899 Member Posts: 3
edited July 2018 in Working with GS (Mac)

I want to stick a knife to a piece of wood when it is thrown kind of like whats shown in the embedded image

image

Comments

  • mikejamesfishermikejamesfisher Member, PRO Posts: 88

    Is the wood going to be moving? If no, then it doesnt seem like you would need to stick the knife to the wood persay. If yes, there is a way to constrain the knife self x,y to the wood self x,y with constrain attribute. That would place knife in center of wood. Add or subtract some off the wood self attribute to off center where it sticks..... is that close to answering your question or making sense?

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

    If you have the wood on a higher layer than the knives (in front of them), then the knives will appear to be stuck in the wood. But there are so many details that you haven't included -- such as the ones @mikejamesfisher asked -- that it's hard to know how you're intending this to work.

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

  • rishabgoyal1899rishabgoyal1899 Member Posts: 3

    @mikejamesfisher yes , the piece of wood will be moving and i want it to stick to the wood and move with it

  • rishabgoyal1899rishabgoyal1899 Member Posts: 3

    @mikejamesfisher thanks for the help

  • JapsterJapster Member Posts: 672

    @rishabgoyal1899 - PS - The method that @mikejamesfisher has pointed you towards is excellent, but I also found an interesting hack for my last game (that I'm sure other veterans are aware of) to make constraining this kind of stuff dead easy...

    It's probably not perfect for all scenarios, and is a little wasteful (larger actors), and uses custom colliders (easy to create, but possibly daunting if you've not used them yet) - purely for smaller, precisely located 'hit boxes', but if your game's not massively 'busy' (ie. like my Courier Chaos game, with 200+ actors in a scene), there's no real performance issue.

    You could use these for the objects around the edge of the piece of wood, the knives, and anything else!

    This is a crap graphic, but basically, small custom collider at the center of the 'log', LONG actors for the apples, knives, etc, again with smaller (half length) custom colliders for the knives (rectangular are fine), and that's probably it. Fire your knives as you would normally, and when the knives collider collides with the centre of the log, simply note the log's rotation (I'd also suggest constraining the log's rotation to a game variable, from inside the Log's behaviours (Also saving X and Y, but if the log doesn't actually MOVE (just rotates), you'll only need to set these once, not constrain them!)) for use an an offset for that knife, then constrain the knife's X,Y to Log's X,Y, and rotation to Log's rotation + the value you saved when you hit the log.

    I'm unfortunately not great at explaining, but this worked REALLY well for me, for open and closed doors, animating them, etc... they stayed in the correct place, opened properly (visually) and the colliders worked great...

    Once you've made your GFX and used Physics Editor to create custom colliders for each actor type (Log, knife, bonus item) (arguably the tedious bit of this solution), then using it is really easy.... It doesn't get easier than constraining X to X, Y to Y, and object's rotation to (Log's rotation + the angle when your knife had 'hit' it).

    (PS The Apple is the same principle as the knife, just that the collider is basically just set around the apple's area.

    If I get a chance, I'll knock up a sample project for you... :smile:

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @Japster -- that sounds like a really great way to do this. I would greatly appreciate an example! (If you have time).

  • JapsterJapster Member Posts: 672

    @RThurman said:
    @Japster -- that sounds like a really great way to do this. I would greatly appreciate an example! (If you have time).

    @RThurman - That's high praise coming from yourself mate! - for you sir, anything! - I owe you a debt for all of your help so far, so more than happy to chuck something together, and tbh, it's the kick I needed, to knock up a sample project for @rishabgoyal1899 ... :wink:

  • JapsterJapster Member Posts: 672
    edited July 2018

    @RThurman said:
    @Japster -- that sounds like a really great way to do this. I would greatly appreciate an example! (If you have time).

    Here you go fella....

    My 'log' is a weird shape (fnarr), just because I was trying to see if I could get it working smoothly despite a weird shape, but my shape isn't properly centred (if it was, it wouldn't even matter if it was rectangular aspect (ie. actor set to say, 180 x 140) - atm it kind of works, but of course, a perfectly central circle would be perfect... (I also didn't bother making the colliders exactly in the centre, as they don't affect it - they're simply there to roughly hit together... :wink: The log graphic being off-centred (hey, it's late, Zzzzzz!), is (I think) also the reason why the apple 'hovers' for want of a better term... :smile:

    Can't see any performance issues... :wink:

    Can't seem to attach a GS project at my end, so zipped it...





    Custom Colliders also attached, for the Log, Knife, and Apple (Note, I created the collider for the apple just now, so it needs selecting for the apple inside GS, if you're going to try the Apple collider logic in the post below!), in case you need to tweak them, or more actors need to be set to them as you go along (as GS doesn't import 'em into projects as re-usable/ source PE collider files), more as direct data, as far as I know?...

  • JapsterJapster Member Posts: 672
    edited July 2018

    PS - if you want to hit the apples etc, then simply create another custom collider, as below, and fire off an invisible 'apple-collision' actor set to this collider, together with your knife, or even simpler, a standard rectangular actor, fired off at the same time, speed etc of your knife, at the right distance from the knife actor to overlay in the same way as to achieve (ie) this collision area:-

    Of course, your apple collider is simply a rough sphere/rectangle even, around the actual apple, placed inside your long apple actor using PE.... Spot-on collisions... :wink:

  • Twayne2Twayne2 Member Posts: 458

    This goes above my head lol. I don't really understand this lol, but it looks cool. =)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @Japster -- Thanks for taking the time to create the demo! I really like the approach you take. I am going to take a couple of days to study this out.

    Much appreciated!

  • JapsterJapster Member Posts: 672
    edited July 2018

    @Twayne2 said:
    This goes above my head lol. I don't really understand this lol, but it looks cool. =)

    Thanks @Twayne2 - appreciated mate - it only takes time, and playing around with the project, and you'll get it... :wink:

  • JapsterJapster Member Posts: 672
    edited July 2018

    @RThurman said:
    @Japster -- Thanks for taking the time to create the demo! I really like the approach you take. I am going to take a couple of days to study this out.

    Much appreciated!

    @RThurman - Hey, no worries! - In the end, I had a second actor 'Stuck Dagger' than can be spawned once the log is hit, for 2 reasons...

    1) it allows me to reduce overhead and have a dedicated actor with 'stuck in log' behaviour, and...

    2) gives more flexibility / tidier logic for the 2 states... easier to maintain, and no dodgy constraining 'fudges' once it's hit the log.

    The logic is really lazy, as it's much easier to match X,Y's of multiple rotating actors by doubling the actors length to 'offset' it to the correct distance more easily, than try to offset it and work around the limitation of having a centre-of-actor-only placement system.

    @Socks of course has awesome mathematical solutions, and lives and breathes COS and SIN, but I just can't get my head around it, so picked the lateral thinking option... :wink:

    Even the apples are easy to work out, as is hitting existing knives (same logic as the apple collider, say, limited to the handle of the knives, then simply spawn, say, 2 half-knives a degree or so either side of the original knife hit, and then destroy it.)

    Same for apples, use an offset to spawn an 'exploding/splitting apple at the 'log' apple actor's position, rotation, plus/minus an offset to spawn it over the apple on the longer actor, using that actor's X,Y,Rotation as the basis, before destroying the 'log' apple. I think it can be quite easy to introduce complex gameplay and actions in the game.... :wink:

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @Japster -- thanks again for the demo. I really like your ideas on how to expand the concept.

  • JapsterJapster Member Posts: 672
    edited July 2018

    @RThurman said:
    @Japster -- thanks again for the demo. I really like your ideas on how to expand the concept.

    @RThurman -Hey, no worries! - I'm sure with your expertise, you can iron out any quirks with it, but yep, the same sort of logic works great in my game, albeit I didn't need rotation, so it was also useful for myself, to knock up that demo!... :smiley:

  • JapsterJapster Member Posts: 672
    edited July 2018

    PS - I only feel it fair to give a huge shout out to @adent42 and co for actually implementing these custom colliders, which have helped me out massively with loads of stuff, including Courier Chaos and Gravity Star Rescue 'n' Racer! - would have been otherwise none-do-able projects! (or severely limited in collision accuracy etc)...

Sign In or Register to comment.