playMaker

Author Topic: Instantiate prefab with force  (Read 1076 times)

2h

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Instantiate prefab with force
« on: June 07, 2016, 03:58:03 PM »
Hi all, I'm new to Playmaker and would associate some advice. 

I simply want to instantiate a prefab and have force immediately applied to it. So for insurance it could be a Canon ball firing from a Canon.

So far I have a mouse click event to trigger, a prefab instantiating, but I'm not sure how to adult force to the prefab.

Any suggestions appreciated.

2h

mdotstrange

  • Hero Member
  • *****
  • Posts: 549
    • View Profile
    • Can't code? Who cares! Make games anyway!
Re: Instantiate prefab with force
« Reply #1 on: June 07, 2016, 04:02:11 PM »
Create an fsm on the canon ball that has the "Add Force" action- just make sure it has a collider and a rigid body component as well-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

2h

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: Instantiate prefab with force
« Reply #2 on: June 08, 2016, 06:24:03 AM »
Hi, thanks for the reply.

I have tried this, but no look getting the force to apply.

I was also thinking the following.

To the projectile object I had added the actionaddForce and also a listener for a mouse click. This meant every instantiation of the projectile had these components.

I was thinking, is it better to have a listener on the canon. When the button clicks, a child object (projectile) is created and is launched with force. This was what I had in mind, but I can't manage to transfer my logic to a playmaker state. I can;t get the force to apply to the projectile.

Any more advice would be appreciated.

2h.

2h

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: Instantiate prefab with force
« Reply #3 on: June 08, 2016, 06:47:03 AM »
Okay, I have it firing now.

I'll attach an image of the State machine, might be of use to another.

The next thing I want to do is have the force match the direction that the canon points.

Following that, a dynamic way to vary the force.

Thanks for the help so far. Any other suggestions or tips appreciated.

2h.


Roger Lee

  • Playmaker Newbie
  • *
  • Posts: 22
    • View Profile
Re: Instantiate prefab with force
« Reply #4 on: June 11, 2016, 04:39:24 PM »
When your cannon ball spawns it should do so with the same x,y,z orientation as the object it's spawning on.  it's just a matter of adding the force in the correct orientation.

Z+ is usually the preferred axis for forward movement.  I see from your pic your force is going in the Y axis.  You can modify the rotation at spawn by opening up the "rotation" section of the create object action.

Below is a pic of the deck cannon system on my submarine.  It doesn't need any special rotation because the cannon bore is oriented with Z pointing forward just like my cannon shell.


« Last Edit: June 11, 2016, 04:54:30 PM by Roger Lee »