Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Micah on April 09, 2018, 04:23:47 PM

Title: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: Micah on April 09, 2018, 04: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?
Title: Re: Reflect/Invert Rotation Values?
Post by: djaydino on April 09, 2018, 04: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
Title: Re: Reflect/Invert Rotation Values?
Post by: Micah on April 09, 2018, 05: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?
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: djaydino on April 09, 2018, 06:06:07 PM
Hi.
With a pong game i made, i made some physics materials and placed them in the colliders from the walls.

Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: Micah on April 09, 2018, 06: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.
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: tcmeric on April 09, 2018, 08: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

(Download whole project, unzip, take out playmaker action  you want).

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.
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: Micah on April 13, 2018, 03:32:02 PM
Okay. I've tried and tried, it rotates, but sadly it just doesn't rotate accurately.
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: Micah on April 15, 2018, 01:18:12 PM
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.
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: djaydino on April 15, 2018, 03: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.
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: Micah on April 15, 2018, 04: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.
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: djaydino on April 15, 2018, 04:21:52 PM
hi,
Maybe you need to get the quaternion or euler angles and try with those values
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: Micah on April 15, 2018, 04: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
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: djaydino on April 15, 2018, 05: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 ?
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: Micah on April 15, 2018, 07:06:05 PM
hmm yeah that works. I just need to calculate the rest.
Title: Re: Reflect/Invert Rotation Values? Bullet Ricochet?
Post by: Micah on April 16, 2018, 06: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.

(https://files.slack.com/files-tmb/T4K5M4D41-FA8RQAYNT-73f67de220/image_1024.png)

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