# playMaker

### Author Topic: Reflect/Invert Rotation Values? Bullet Ricochet?  (Read 533 times)

#### Micah

• Playmaker Newbie
• Posts: 22
##### Reflect/Invert Rotation Values? Bullet Ricochet?
« on: April 09, 2018, 01:23:47 PM »
Is there a way to Reverse or Invert Rotation values? I'm trying to make a projective reflect off walls etc. I have been able to do so with transform, get collision info, Get position and Vector3.Reflect, but the rotation remains the same. So I tried Get Rotation with Vector3.reflect but to no avail. Is there any solution to this?
« Last Edit: April 09, 2018, 02:32:01 PM by Micah »

#### djaydino

• Hero Member
• Posts: 3384
##### Re: Reflect/Invert Rotation Values?
« Reply #1 on: April 09, 2018, 01:48:34 PM »
hi.
To get the opposite from a float i do a multiply by -1

You could try this with a Vector 3 operator

#### Micah

• Playmaker Newbie
• Posts: 22
##### Re: Reflect/Invert Rotation Values?
« Reply #2 on: April 09, 2018, 02:31:25 PM »
Okay So I did it. But it seems my theory Didn't work. *sigh* Is there any other way to do reflection or ricochet and have the object face the direction it is traveling in?

#### djaydino

• Hero Member
• Posts: 3384
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #3 on: April 09, 2018, 03:06:07 PM »
Hi.
With a pong game i made, i made some physics materials and placed them in the colliders from the walls.

#### Micah

• Playmaker Newbie
• Posts: 22
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #4 on: April 09, 2018, 03:27:22 PM »
Yeah Yeah I've tried that and it works, the problem is the direction. The object doesn't "Face" the direction it is travel
ing in. So say there is an arrow pointing 55 degrees, when it bounces off the wall, instead of rotating and facing the new direction it  is now moving.

I got another idea. I'll try "Get Angle to Target", then "float subtract", then "float multiply by -1" and use that value to rotate the object.

Edit: LMAO That failed miserably........

Edit: Okay, I'm goin to see if I can get the angle of the normal and use the angle and x by 2 to get the full ricochet angle. I'm not a genius at maths as you can see. I'm just spit balling.
« Last Edit: April 09, 2018, 04:12:26 PM by Micah »

#### tcmeric

• Hero Member
• Posts: 648
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #5 on: April 09, 2018, 05:04:31 PM »
You can try and get the direction that the object is heading, and then rotate it to face the correct way.

There is an action for that in my github, under projectiles: https://github.com/dumbgamedev/general-playmaker

While you object is flying, get the vector 3 position. Wait 1 - 2 frames. Then get again. Now you have position 1 and position 2. Use the get direction vector 3 action, to get the direction. Use this to rotate your object.

#### Micah

• Playmaker Newbie
• Posts: 22
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #6 on: April 13, 2018, 12:32:02 PM »
Okay. I've tried and tried, it rotates, but sadly it just doesn't rotate accurately.

#### Micah

• Playmaker Newbie
• Posts: 22
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #7 on: April 15, 2018, 10:18:12 AM »
right. So I revisited my original idea which will probably set the president for designing my game. I used math but separated horizontal surfaces (facing Y) and vertical surfaces (facing X). It works. However there is one problem. For the Horizontal surfaces, I am using a float compare to determine if the value is higher than 0. So if Float 1 (Y Rotation) is lower than Float 2 = Subtract by 100, if Float 1 is greater than float 2 = Add 100.

What am I doing wrong? Because if the Float 1 is -41 for example, it still acts as if it is greater than 0, like playmaker sees it as 41 instead of -41. I tried swapping Float 1 and float 2 but the Opposite happens.
« Last Edit: April 15, 2018, 10:22:50 AM by Micah »

#### djaydino

• Hero Member
• Posts: 3384
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #8 on: April 15, 2018, 12:45:15 PM »
Hi,
Have tested with some break points?

I don't think the issue is on the float compare action, but on the rotation value.

#### Micah

• Playmaker Newbie
• Posts: 22
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #9 on: April 15, 2018, 01:03:04 PM »
Okay I Put the transition to none so that I can see it. Yeah the rotation isn't -41 in the scene its something like 314.

#### djaydino

• Hero Member
• Posts: 3384
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #10 on: April 15, 2018, 01:21:52 PM »
hi,
Maybe you need to get the quaternion or euler angles and try with those values

#### Micah

• Playmaker Newbie
• Posts: 22
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #11 on: April 15, 2018, 01:43:40 PM »
Those values seem to be what the problem is. I need to be able to turn 314 into -41 otherwise the calculation wont work
« Last Edit: April 15, 2018, 01:47:03 PM by Micah »

#### djaydino

• Hero Member
• Posts: 3384
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #12 on: April 15, 2018, 02:15:21 PM »
Hi,
I looked a bit on the unity forums
and a solution i found was to check if greater than 180 and if so deduct 360 to get the -value like on the inspector.

But maybe you can try to compare if higher or lower that 180 instead of 0 ?

#### Micah

• Playmaker Newbie
• Posts: 22
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #13 on: April 15, 2018, 04:06:05 PM »
hmm yeah that works. I just need to calculate the rest.

#### Micah

• Playmaker Newbie
• Posts: 22
##### Re: Reflect/Invert Rotation Values? Bullet Ricochet?
« Reply #14 on: April 16, 2018, 03:05:52 PM »
Okay so I pretty much achieved the deflection/Reflection off surface mechanic. I feel like I've wasted a week, but I've done it. To a standard that I like as well. Was a mighty ball ache though. I've had to use a lot of math and the actions and events are all over the place.

he reflections are not 100% accurate But it will have to do.