So in my game, I have these boats with cannons on them, and I want the cannons to be able to point and shoot towards the player’s mouse, with a limited range of motion, sort of like the cannons from Galleons
But whenever I tried to do this by changing the orientation of the cannon’s CFrame, it’d instead move the entire boat. I also tried doing this with a hinge, but the target angle only works on 1 axis.
You can use a weld and manipulate the C0 or C1 property directly. This will not cause the entire boat to move. This works in any axis too but you only need to manipulate 2 in this case.
Alright thanks, I can get it rotating and moving without displacing but the boat, but I’m struggling to figure out how to get it pointing towards the mouse properly.
In a local script, I get the mouse.Hit and send it through a server event.
But I’m not sure how to get that to actually translate to point the cannon towards the mouse.
This is what I’m currently doing but it just moves the cannon and the direction isn’t accurate.
Well, the way the code works right now (based on what is given) is that the cannon only moves after the mouse is clicked, which fires an event to the server.
If you want the cannon to move to the mouse position constantly, you would have to constantly update the CFrame.lookAt value. The video seems to make the cannon’s aim correct, so I am not sure what you mean by:
Well that was just an example of what I’m trying to get from another game, what happens to mine is it just goes to a completely random angle and position, so something is wrong with the C0 CFrame but I don’t know what’s going on.
But the problem is I can’t manipulate the CFrame of the cannon itself because it has to be welded to the boat in order to move with it, but if I move it while it’s welded, it moves the entire boat with it.