Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Fat Pug Studio on June 24, 2016, 07:25:18 AM

Title: Reflecting bullet FSM
Post by: Fat Pug Studio on June 24, 2016, 07:25:18 AM
Hello all!

I am trying to make a bullet reflect off a collider in 2D game, but i just can't get my head around it. I checked out the breakout sample game, but that's not quite it since it has a fixed reflection angle based on impacting left or right collider of the paddle and the brick, as far as i have seen. There are some pinball playmaker games, but i think there's also no reflection there, just adding force to the ball when hitting the flipper. I googled a lot, and even found some scripts, but nothing does the job unfortunately. I think it can be done fairly simple in Playmaker, but i need some help.

The bullet has a fixed velocity (not force), so upon colliding it only needs to change direction whle keeping the velocity. I am aware i need to use vector3 reflect under the operator advanced action and i've read about the normal of the impact and calculation of the exit angle and thus the rotation that needs to be applied to the bullet but don't quite know how to implement it.

Any help or example is welcome!
Title: Re: Reflecting bullet FSM
Post by: cwmanley on June 25, 2016, 12:07:16 AM
Velocity (X,Y) -1 , will reverse the direction.

GetVelocity2d/Math/SetVelocity2d

 :)
Title: Re: Reflecting bullet FSM
Post by: Fat Pug Studio on June 25, 2016, 03:35:34 PM
Yes, but what should be the math part ;D
Title: Re: Reflecting bullet FSM
Post by: cwmanley on June 25, 2016, 04:10:53 PM
The Math is " Velocity (X,Y) -1 "


 :)
Title: Re: Reflecting bullet FSM
Post by: Fat Pug Studio on June 26, 2016, 05:00:11 AM
Works good, the thing is, how to i set it to reflect under angle when colliding with circle collider?
Title: Re: Reflecting bullet FSM
Post by: cwmanley on June 26, 2016, 02:22:38 PM
Sorry, I did not think it all the way through. This should work.

Title: Re: Reflecting bullet FSM
Post by: Fat Pug Studio on June 27, 2016, 06:43:37 AM
Thank you,

you are very kind, i will try it out  ;D
Title: Re: Reflecting bullet FSM
Post by: Fat Pug Studio on June 27, 2016, 08:14:43 AM
Hmm, the thing is, the object that's being hit actually ricochets under angle, but the object that should ricochet stops when it hits the target :-\
Title: Re: Reflecting bullet FSM
Post by: RC on June 27, 2016, 11:26:41 AM
I'm also having trouble figuring this out, My issue with this fsm is when my bullet hit a surface, it will bounce back only either on the x or y axis.

It doesn't go in the angle even the bullet is traveling at an angle.
Title: Re: Reflecting bullet FSM
Post by: cwmanley on June 27, 2016, 03:39:27 PM
Thanks,

This is a little better, but the "bullet" can stop if it makes constant contact with something like a object moving in the direction it is traveling. 

Changing layers after the collision might be solution.

Title: Re: Reflecting bullet FSM
Post by: RC on June 27, 2016, 04:57:05 PM
Awesome! Thank you!
Title: Re: Reflecting bullet FSM
Post by: Fat Pug Studio on June 28, 2016, 02:07:08 AM
have you managed to get it working rongconcrx? My bullet just hits the ball and stops.
Title: Re: Reflecting bullet FSM
Post by: Fat Pug Studio on June 28, 2016, 05:46:44 AM
I've found an elegant solution. Since i need the reflection to ricochet the bullets off of shield of an enemy, i can simply set the bouncy physics material to shield and set bounciness to 1 so the bullet doesn't lose power and flip the sprite.

Expansion of the idea would be even better, a shield could change the physics material according to the tag of the bullet, so some bullets would pass, some would reflect, depending of the type of the bullet. Alas, there's no action for setting the physics material either :(
Title: Re: Reflecting bullet FSM
Post by: cwmanley on June 30, 2016, 09:56:28 PM
I am sorry my solution did not work, but I am glad you found a solution you like.

If your still having trouble, I am glad to help as much as I can.

Thanks
Title: Re: Reflecting bullet FSM
Post by: Fat Pug Studio on July 05, 2016, 05:21:20 AM
Hey, sorry gor late response, i've been quite busy. Thanks a lot for the help, you really gave yourself there, it gave me insight in how things work and i'm sure i'll make it work somehow and share the template with everyone. Until then, Jean made set physics material 2d action and the sprite can be flipped via action so making bullets bounce now is a no brainer!
Title: Re: Reflecting bullet FSM
Post by: dvir on November 22, 2020, 03:43:20 AM
I created an fsm exactly like the last image but it doesn’t even move.

Does anyone know why?
Title: Re: Reflecting bullet FSM
Post by: djaydino on November 22, 2020, 09:01:34 AM
Hi.
There is a sample scene on this post, maybe that can help :
https://hutonggames.com/playmakerforum/index.php?topic=13078.msg61217#msg61217
Title: Re: Reflecting bullet FSM
Post by: dvir on November 23, 2020, 03:36:49 AM
“Until then, Jean made set physics material 2d action and the sprite can be flipped via action so making bullets bounce now is a no brainer!”

What does that mean?