# playMaker

### Author Topic: Reflecting bullet FSM  (Read 4823 times)

#### Fat Pug Studio

• Beta Group
• Hero Member
• Posts: 1236
##### Reflecting bullet FSM
« 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!
Available for Playmaker work

#### cwmanley

• Full Member
• Posts: 107
##### Re: Reflecting bullet FSM
« Reply #1 on: June 25, 2016, 12:07:16 AM »
Velocity (X,Y) -1 , will reverse the direction.

GetVelocity2d/Math/SetVelocity2d

#### Fat Pug Studio

• Beta Group
• Hero Member
• Posts: 1236
##### Re: Reflecting bullet FSM
« Reply #2 on: June 25, 2016, 03:35:34 PM »
Yes, but what should be the math part
Available for Playmaker work

#### cwmanley

• Full Member
• Posts: 107
##### Re: Reflecting bullet FSM
« Reply #3 on: June 25, 2016, 04:10:53 PM »
The Math is " Velocity (X,Y) -1 "

#### Fat Pug Studio

• Beta Group
• Hero Member
• Posts: 1236
##### Re: Reflecting bullet FSM
« Reply #4 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?
« Last Edit: June 26, 2016, 05:03:49 AM by krmko »
Available for Playmaker work

#### cwmanley

• Full Member
• Posts: 107
##### Re: Reflecting bullet FSM
« Reply #5 on: June 26, 2016, 02:22:38 PM »
Sorry, I did not think it all the way through. This should work.

#### Fat Pug Studio

• Beta Group
• Hero Member
• Posts: 1236
##### Re: Reflecting bullet FSM
« Reply #6 on: June 27, 2016, 06:43:37 AM »
Thank you,

you are very kind, i will try it out
Available for Playmaker work

#### Fat Pug Studio

• Beta Group
• Hero Member
• Posts: 1236
##### Re: Reflecting bullet FSM
« Reply #7 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
Available for Playmaker work

#### RC

• Full Member
• Posts: 145
##### Re: Reflecting bullet FSM
« Reply #8 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.

#### cwmanley

• Full Member
• Posts: 107
##### Re: Reflecting bullet FSM
« Reply #9 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.

#### RC

• Full Member
• Posts: 145
##### Re: Reflecting bullet FSM
« Reply #10 on: June 27, 2016, 04:57:05 PM »
Awesome! Thank you!

#### Fat Pug Studio

• Beta Group
• Hero Member
• Posts: 1236
##### Re: Reflecting bullet FSM
« Reply #11 on: June 28, 2016, 02:07:08 AM »
have you managed to get it working rongconcrx? My bullet just hits the ball and stops.
« Last Edit: June 28, 2016, 02:34:57 AM by krmko »
Available for Playmaker work

#### Fat Pug Studio

• Beta Group
• Hero Member
• Posts: 1236
##### Re: Reflecting bullet FSM
« Reply #12 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
« Last Edit: June 29, 2016, 10:10:25 AM by krmko »
Available for Playmaker work

#### cwmanley

• Full Member
• Posts: 107
##### Re: Reflecting bullet FSM
« Reply #13 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
« Last Edit: June 30, 2016, 10:07:12 PM by cwmanley »

#### Fat Pug Studio

• Beta Group
• Hero Member
• Posts: 1236
##### Re: Reflecting bullet FSM
« Reply #14 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!
Available for Playmaker work