playMaker

Author Topic: How to swap characters?  (Read 2410 times)

Frost

  • Playmaker Newbie
  • *
  • Posts: 16
How to swap characters?
« on: June 19, 2018, 06:05:42 PM »
Hello again PlayMaker forum! Im making a 2D platformer game where i have two characters and want to swap them when they collide with an image then they swap. I tried OnTrigger Enter 2D collisioning with a trigger tag (trigger tag) to create new object (the other player) and destroy self but doesnt work at all. Any ideas on how to do this?
« Last Edit: June 19, 2018, 06:34:25 PM by Frost »

Frost

  • Playmaker Newbie
  • *
  • Posts: 16
Re: How to swap characters?
« Reply #1 on: June 19, 2018, 09:38:58 PM »
After adding a Box Collider (Trigger checked) and a Rigidbody 2D to the trigger object (something that makes the player swap and can go across it) actually works but in unexpected way... the trigger is working and my character get destroyed. But the other character is not spawning in its place with Create Object... any ideas?

Frost

  • Playmaker Newbie
  • *
  • Posts: 16
Re: How to swap characters?
« Reply #2 on: June 19, 2018, 10:53:13 PM »
Ok now it seems to be working out nicely excepts that the camera is stuck where the initial character was destroyed, is like is not following the newly spawned character. Any ideas how to fix this?

Frost

  • Playmaker Newbie
  • *
  • Posts: 16
Re: How to swap characters?
« Reply #3 on: June 19, 2018, 11:01:38 PM »
Ok now it works but the camera is showing nothing except the player and the empty minimap... any help, please?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to swap characters?
« Reply #4 on: June 20, 2018, 04:29:45 AM »
Hi.
if you need to swap regularly i think its better to use activate/deactivate instead of Create/destroy (better for performance)

Do you have the character inside a parent? (where parent does all the movement/camera follow etc.)

Frost

  • Playmaker Newbie
  • *
  • Posts: 16
Re: How to swap characters?
« Reply #5 on: June 20, 2018, 08:10:06 AM »
Hi djay. No im not using a parent, each character do the movement different so parenting without any idea to code would not work. I have two characters and they behave very different. When i hit the trigger my character swaps correctly and moves correcly but the camera doesnt follow him. Im stuck here...

Thanks for the activate/deactivate idea i will try that now :)

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: How to swap characters?
« Reply #6 on: June 20, 2018, 09:17:28 AM »
It's always better to post screenshots of your actions, then we don't have to guess have your setup is.

My initial thought is that you need to set the camera target to the new object?

verybinary

  • Junior Playmaker
  • **
  • Posts: 81
    • The Museum of Digital
Re: How to swap characters?
« Reply #7 on: June 20, 2018, 03:47:38 PM »
create an empty. put your controls on this empty, put your two players(with animations) both in this empty. deactivate one of the players. do your trigger thing, and when it triggers, activate the other one and deactivate the current one.

Frost

  • Playmaker Newbie
  • *
  • Posts: 16
Re: How to swap characters?
« Reply #8 on: June 20, 2018, 04:10:54 PM »
Ok so here are my PlayMaker images of what im trying to do

Ok the images dont seem to work so here is my DropBox shared folder.

https://www.dropbox.com/sh/6mvjxu8xuj4t2v4/AACLNU6tOy4rfAckoLAjbAwja?dl=0









« Last Edit: June 20, 2018, 04:16:16 PM by Frost »

Frost

  • Playmaker Newbie
  • *
  • Posts: 16
Re: How to swap characters?
« Reply #9 on: June 20, 2018, 04:36:21 PM »
Basically:

Start > Trigger Exit 2D with player > Swap > Deactivate Player 1 > Transform > Activate Player 2

The result work but the camera doesnt follow Player 2 and i dont know who to do this
« Last Edit: June 20, 2018, 04:39:31 PM by Frost »

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: How to swap characters?
« Reply #10 on: June 20, 2018, 06:48:25 PM »
Yes, you need to change the target in your camera script for it to follow another object/character.

If you're not sure about how to do it, have a look at this:
http://www.smalljelly.com/home/2016/7/29/playmaker-guide-get-component-get-property-set-property-with-instantiated-prefabs

Frost

  • Playmaker Newbie
  • *
  • Posts: 16
Re: How to swap characters?
« Reply #11 on: June 20, 2018, 07:10:11 PM »
Yes, you need to change the target in your camera script for it to follow another object/character.

If you're not sure about how to do it, have a look at this:
http://www.smalljelly.com/home/2016/7/29/playmaker-guide-get-component-get-property-set-property-with-instantiated-prefabs

Thanks for the link i will check it out as i have been struggling to do that. Time to look into prefabs