playMaker

Author Topic: embarrassing to ask but - 2D rise up style interaction  (Read 1430 times)

tyrot

  • Playmaker Newbie
  • *
  • Posts: 17
embarrassing to ask but - 2D rise up style interaction
« on: February 14, 2020, 06:27:54 AM »
Never tried 2D before so i am an alien to 2D actions.


I have checked C# tutorials it looks easy but i cannot recreate this on Playmaker.

-this is one version i want to imitate
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDefender : MonoBehaviour {

//This is the cursor/crosshair/mouse that will be used to defend the balloon with.

public Rigidbody2D Rigidbody2D;
public AudioClip HitSound;

void Start () {
Vector2 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Rigidbody2D.position = mousePos;
}

void OnCollisionEnter2D(Collision2D col) {
GetComponent<AudioSource>().PlayOneShot(HitSound, 7.7F);

}

void Update () {

Vector2 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Rigidbody2D.position = mousePos;

}
}

This version has Rigidbody 2 and point effector attached.
Some other codes have no point effector.

Please put me in the right direction ..

 

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: embarrassing to ask but - 2D rise up style interaction
« Reply #1 on: February 14, 2020, 06:36:05 AM »
Hi,

make an fsm with a state and all action should execute everyframe.

1: get the mouse position using GetMouseX and GetMouseY
2: Make a vector out of it
3: use that vector in ScreenToWorldPoint action to get a world position of your mouse
4: use the custom action RigidBody2dMovePosition to position the 2d object under the mouse using the world position you got in point 3

the rest is to be setup in your rigidbody and gameobject collider itself. you can make more fsm to trigger sounds, etc, but that's already a different topic.


Bye,

 Jean

tyrot

  • Playmaker Newbie
  • *
  • Posts: 17
Re: embarrassing to ask but - 2D rise up style interaction
« Reply #2 on: February 14, 2020, 06:37:23 AM »
wow - a reply less than 10 min! THANKS JEAN i will try it right away!

tyrot

  • Playmaker Newbie
  • *
  • Posts: 17
Re: embarrassing to ask but - 2D rise up style interaction
« Reply #3 on: February 14, 2020, 07:48:14 AM »
Hello Jean,
I made as you said.
1: get the mouse position using GetMouseX and GetMouseY

Done.

2: Make a vector out of it

I thought first i gotta make Vector 2 but ScreenToWorldPoint requires vector 3 so i set a vector 3 - and zero out Z axis = V3_setVector

3: use that vector in ScreenToWorldPoint action to get a world position of your mouse
I use that "V3_setVector" and i stored World Vector "V3_S2W" camera is at z -10 so it adds that -10 to Vector "V3_S2W"

Is there anything i m doing wrong so far? Because
Rigidbody2D move position does not move collider at all .. even though i see numbers..
« Last Edit: February 14, 2020, 07:59:47 AM by tyrot »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: embarrassing to ask but - 2D rise up style interaction
« Reply #4 on: February 17, 2020, 01:55:19 AM »
Hi,

 yeah :) don't expect a 10 mn latency on every reply though... if after a few days you haven't heard back, ping the thread, and/or pm me directly.

your issue could be in your scene/object/component setup itself. Is your rigidbody set to iskinematic? is it free ( unparented), etc. there could be many factor indeed.

Let me know, and maybe send me the test scene if you can't debug it further.

Bye,

 Jean

tyrot

  • Playmaker Newbie
  • *
  • Posts: 17
Re: embarrassing to ask but - 2D rise up style interaction
« Reply #5 on: February 17, 2020, 07:08:06 AM »
thank you jean . I will check your suggestions and reply back to this thread.

But i wanna ask one more thing.

I have a parent object and it has 3 children. I want to deactivate this parent object after its children deactivated. How to approach this... I think i have checked all the custom actions still could not figure out.

I have couple of objects in Array variable. Each object has its children. Before i loop to next Array object i wanna make sure all the children of that object is deactivated..

Thank you once again.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: embarrassing to ask but - 2D rise up style interaction
« Reply #6 on: February 17, 2020, 07:34:12 AM »
Hi,

 you'll need to do that manually, you can make an fsm template that goes on each child, then you fire a global event from the parent to its children, that template catch it and deactivate all its children using custom actions, then from the parent you can further proceed.

Bye,

 Jean