It doesn’t look like it worked. Try this, comment out the line of code moving the mortar and move your mouse around the mortar in a couple of slow circles.
I should have did that first to be honest. Not sure why I didn’t
No worries. I hadn’t thought of that until now either. lol
I’ve tried it out, but you’d have to move your mouse really far to the right to get it to go to a positive value.
Would we not be able to use a cross product on the X and Z axis for this?
Hold on for a bit. I know there is a way to do this. But I always do it the wrong way a couple of times first. Try this instead:
local x=nozzle.CFrame:PointToObjectSpace(B)
print(x.Z)
B is a Vector2 btw. I’m guessing I should do a Vector3.new(B.X, 0, B.Z)?
Right. Forgot about that. Might be Vector3.new(B.X, 0, B.Y) however. I’ll try some stuff in studio to see if I can get this working.
https://gyazo.com/efc0373ad88dc449e8503fa15a7c4d9c.gif
The value isn’t moving much at all now, might be more of what you expected.
-258.69766235352 (x182)
-257.59930419922
-257.65594482422 (x3)
-258.57473754883
-258.75149536133 (x4)
After playing a bit around in studios, it seems to be something more like this:
local B=workspace.Target.Position
local x=workspace.Nozzle.CFrame:PointToObjectSpace(B)
print(x.Z)
Try that and tell me how the numbers change.
Update: Just realized we tried this but thought it didn’t work. I think the nozzle is just not rotated in the right way. Try this like you did before but with the moving of the motar off and doing slow circles.
It’s possible this is working, just not on the right axis
You get a positive/negative value as you would expect on the Red line,
but it takes a bit more distance to do so on the blue line.
If you drew a circle around the motar and cut it in half, which side gives you positive numbers and which gives you negative? Just a little confused on where you get your values of negative and positive.
Yellow is positive, Red is negative. Blue is the circle. I mean… it really is the circle though.
The boxes for the red is also the distance needed to go get those values. Just a rough estimate though
I want to know all the points that give you negative and all the points that give you positive. I think you gave me a couple points? But over all is it like this:
top left of the mortar gives you a negative number and bottom right gives you a positive? I have an idea on how to get your motar to completely work. But I need to know this one thing.
I just did some double checking and indeed it’s like this.
Oh is the nozzle that yellow tip? I think the line might be on that. Were going to need to use a different part if that’s the nozzle.
Yep the nozzle is the yellow tip. I made it visible so I could actually figurew out which part was the front of the nozzle. And the nozzle is indeed pointing forwards where it should.
Is there a part positioned on or near one of the attachments used for the hinge constraint?
Yep this blue part. It also rotates with the mortar tube if that’s what your asking.
Could you show me your code right now. Things are going to need to be tweaked.
local Baseplate = Mortar:FindFirstChild("Baseplate")
local Base = Mortar:FindFirstChild("Base")
local Nozzle = Mortar:FindFirstChild("Nozzle", true)
--local Tube = Base:FindFirstChild("Tube")
local MaxElevation = 45
local MinElevation = 15
local A = Baseplate.CFrame.RightVector * -1
A = Vector2.new(A.X, A.Z)
local B = ( Vector3.new(Hit.X, Baseplate.CFrame.Y, Hit.Z) - Baseplate.CFrame.p ).Unit
B = Vector2.new(B.X, B.Z)
local Cost = ( A:Dot(B) ) / (A.Magnitude * B.Magnitude)
local T = math.acos(Cost)
local B = Hit.p
local X = Nozzle.CFrame:PointToObjectSpace(B)
print(X.Z)