playMaker

Author Topic: A simple 2d collision[SOLVEd]  (Read 9606 times)

snortch

  • Playmaker Newbie
  • *
  • Posts: 31
A simple 2d collision[SOLVEd]
« on: August 05, 2014, 10:22:47 AM »
I can't seem to get my basic collision to work correctly. I want my sprite to translate up, hit an object that has a box collider on it, and reverse direction.

Here's what I did to try to make this work:
http://www.screencast.com/t/CP4CzUipjDf

What am I missing?
« Last Edit: August 18, 2014, 04:11:55 AM by jeanfabre »

Redhawk

  • Junior Playmaker
  • **
  • Posts: 57
Re: A simple collision
« Reply #1 on: August 05, 2014, 10:31:22 AM »
Not 100% sure, but you probably want a Collision Detection FSM that only checks for collision and if it is true, you set a public bool to true.  Then your FSM go up/down could check that bool every frame to test if true or not.  If true, you would change direction.

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 715
    • Flashing Lights
Re: A simple collision
« Reply #2 on: August 05, 2014, 10:45:44 AM »
Hello,
it looks like "boss" dont have a collider in video, thats why it wont get collision. And set rigidbody Use gravity+kinematic, I think collider needed gravity in background for collisions.

Im not sure if this technic is convenient for 2d.

Maybe its ok to move the boss towards two empty gameObjects up and down?


snortch

  • Playmaker Newbie
  • *
  • Posts: 31
Re: A simple collision
« Reply #3 on: August 05, 2014, 11:31:02 AM »
@600 - You're right, there wasn't a box collider on that sprite. I was trying to use a rigidbody instead to see if that would work. I just tried putting a box collider on to see if that would make a difference, and it didn't. The sprite still isn't colliding. Before applying the box collider, I also tried setting the rigidbody 'gravity' to on. That also didn't do anything. I haven't tried changing the collision cubes to game objects. If I did - what would I do differently?

@Redhawk. Still trying to implement your idea.

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 715
    • Flashing Lights
Re: A simple collision
« Reply #4 on: August 05, 2014, 11:39:12 AM »
The idea about gameObjects was to make two Empty gameObjects in the scene, in those positions you want the boss to move.
Then without collisions and rigidbody stuff use action "Move Towards" on the boss.
On finish change targets (those Empty gameobjects).

snortch

  • Playmaker Newbie
  • *
  • Posts: 31
Re: A simple collision
« Reply #5 on: August 05, 2014, 11:53:30 AM »
Ohhh- I see. If I can't figure out how to get collisions to work, I will follow your gameobject suggestion. Thanks for this.

snortch

  • Playmaker Newbie
  • *
  • Posts: 31
Re: A simple 2d collision
« Reply #6 on: August 06, 2014, 04:12:35 PM »
Well - I don't feel willing to give up on collisions just yet. After digging into the forum and noticing a few related questions, I've discovered a couple of things:

1. In order for collisions to work in a 2d game, you have to install the Playmaker Unity 2D package (https://hutonggames.fogbugz.com/default.asp?W1150).
2. When that's installed in Unity, you still have to instantiate the 2d prefab in your project.
3. You get a bunch of 2d specific actions after this is installed.
4. I now understand how States and Transitions/Events work. I was thinking about these backwards.

With that new understanding articulated, I'm still stuck. I still can't get my simple collision to work. I can't figure out why this doesn't work... Here's another video that shows what I've done:
http://www.screencast.com/t/I2FZ8qHKzd

Would be super cool if I could get this to work.

PlaymakerNOOB

  • Full Member
  • ***
  • Posts: 219
Re: A simple 2d collision
« Reply #7 on: August 06, 2014, 09:33:25 PM »
its hard to tell from the video, but I think your missing the following:  https://hutonggames.fogbugz.com/default.asp?W1150

Game Object using Physics 2D Setup

In order for Fsm to receive Physics 2d global event, you need to drop a "PlayMakerUnity2DProxy" component on that GameObject. Then, any Fsm on that GameObject will be able to implement the global events "TRIGGER XXX 2D" and "COLLISION XXX 2D". The proxy is also used to store raycasting infos. Any other actions do not requires the proxy component, for example, AddForce2d works fine as is.

Use the Menu "PlayMaker/Addons/Unity 2D/Components/Add PlayMakerUnity2DProxy to Selection" to do so conveniently.

snortch

  • Playmaker Newbie
  • *
  • Posts: 31
Re: A simple 2d collision
« Reply #8 on: August 07, 2014, 09:37:26 AM »
@PlaymakerNOOB. I hadn't tried adding the PlayMakerUnity2DProxy component onto each object. Actually, from the way its described in that wiki article, its not clear if 'each' game object should have the PlayMakerUnity2DProxy component added to it OR only game objects that are involved with global events.

Figuring that there would be no harm in experimenting, I went ahead and added the PlayMakerUnity2DProxy component to each element that is involved with the collision. Being a noob myself, I'm not sure if a cube is considered to be a "game object"? I also decided to simplify my collision FSM. Now it just has two states:

http://www.screencast.com/t/m7AbJrZWHC

I'm still not getting a collision. I even tried swapping out all the 2d collision stuff for regular box colliders and I used the regular COLLISION ENTER events - didn't work there either  >:(

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: A simple 2d collision
« Reply #9 on: August 08, 2014, 03:03:08 PM »
Hi,

 I think you are getting lost. Start with a brand new empty scenes and two cubes and get it to work there. Maybe a free falling cube fall onto another that is set to is kinematic or that is not subject to gravity for example and start from there.

 be careful to properly setup your physics, you need rigidbody, you need concave colliders, you need proper physics layer matching for collisions, that's the basics, then you may ahve issues with too thin colliders and the object goes trhough in between two iterations of the physics engine and the collision is missed, it happens in cases where objects speed is great for example.

 Bye,

 Jean

Fahrettin

  • Junior Playmaker
  • **
  • Posts: 62
  • Noob
Re: A simple 2d collision
« Reply #10 on: August 09, 2014, 06:47:38 AM »
Do you want something like this ?

http://www.screencast.com/t/dp9xg7idRa9D

snortch

  • Playmaker Newbie
  • *
  • Posts: 31
Re: A simple 2d collision
« Reply #11 on: August 09, 2014, 11:10:23 AM »
Yes! This is close. I need two collisions, but if I can get one to work, I can get the other.

Fahrettin

  • Junior Playmaker
  • **
  • Posts: 62
  • Noob
Re: A simple 2d collision
« Reply #12 on: August 09, 2014, 12:02:48 PM »
In my project that grass texture is kind of despawn point. I will put out it to off screen. I tried with cube like you but my characters passed through it.
Then i install playmaker 2d addon. After that i used 2d actions and now it works.

I cant use rigigbody on characters because they kill each other. So i put rigidbody to the grass texture. (Add rigidbody 2D)
http://www.screencast.com/t/3KYqPUpNhYh

Enemy character has just 2D collider.
http://www.screencast.com/t/f2zAqxeA

Than i used 2D action.
http://www.screencast.com/t/dsokev2P
« Last Edit: August 19, 2014, 07:48:04 AM by Fahrettin »