Figuring out when a player does a 360

Hey everyone!

I was wondering what the best way to tell when a player or part has completed a in air rotation.

Such as a 360 spin or other orientation related movement.

I already created a script that fires a function when a player spins their character around 360 degrees while mid air using some basic math. However, it is not very consistent.

How would you guys go about doing this?

2 Likes

I would modify the core scripts which the cameras use, find where they apply the delta changes to the camera pan for any mouse movement, add that up and calculate based off those numbers.

The reason I have not tries this already, is because my games core scripts are completely modified, and I don’t even use half of them. I custom made most of the camera movement and character movement scripts, therefore I can’t use roblox’s stuff to my advantage. I should have mentioned this in the post, but I need to somehow make the calculations based off of HumanoidRootPart orientation or CFrame data. Unless someone else can find another way to do it, of course.

Surely if it’s your own game scripts, it would be easy to sum up the mouse movements and calculate how many degrees they would have rotated from that?

The player does not move their camera with the mouse as most games do.

Appreciate the thought though!

I would probably get the angle of the look vector when the user initially jumps, then on each frame get the delta angle of their lookVector and at it to a revolution counter variable, if it turns 360 degrees relative to its initial start angle you can say it’s done x revolutions. e.g. track this:

local d = math.atan2(-part.CFrame.lookVector.x, -part.CFrame.lookVector.z)

current_ang = current_ang + d

if math.deg(current_ang) % 360 == 0 then
-- stuff
end

Obviously needs to be more developed than that, you need to track the intial angle as I said, and then figure out whether it’s a full revolution relative to that

1 Like

This is basically what I’m doing right now. The part I’m struggling with is tracking past 360, since orientation resets at 360 back to 0 degrees.

It’s hard to track the total rotation since it doesn’t continue past 360, and instead starts over at 0.

You know what I mean.

If you make it past 360 and do a 380 degree spin for instance, you just end up with a 20 degree spin.

What would you do about this?

So this is why I had a variable referenced as ‘current_ang’, if you measure the delta angle at each frame, you can continuously add this to the ‘current_ang’ variable, so you end up with a variable defining the total rotational movement of the object. You can then determine if it’s rotated 360 or more

1 Like

Thank you so much. I will create something that works like this. I was trying to do the calculations based off of the final difference between the orientations, but I will need to be tracking it all throughout the jump.

I appreciate the help!

Just dm me if you struggle to implement it and will give you a hand

2 Likes