Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Hinge Constraint Servo is Buggy in Online Mode?

Asked by 8 years ago
Edited 8 years ago

I am trying to make a game including Tanks. I have custom coded a suspension system and movement system, and those work fine in online mode, online mode being the testing server, not the studio "Play" mode. Recently, I've been experimenting with finally getting a turret I've had connected to my main hull finally aiming with the mouse, using the servo actuator type on the hinge constraint I used to connect it. In solo mode (Studio's "Play" mode) it works absolutely perfectly. Problem is, once I tested it on the server, it began to go crazy, and seemed laggy like it was processing on the server, not the client like I'd specified using setNetworkOwner() for all parts of my tank model. A bit of experimentation later, and I find that GetNetworkOwner() is returning nil on the parts I had specifically set to the controlling player, using a remote function. Going further, I decided to add a delay between spawning and activating the servo on the constraint. What do you know, everything went smoothly until the servo activated, and made everything go crazy again, as you can see in this video

The servo activates 5 seconds after spawning, where the tank begins to flip out. I'd appreciate any help I can get.

Script for aiming the gun:

if playerVehicle and turret and gun and turretHinge then    
        local cameraRay = Ray.new(camera.CFrame.p, camera.CFrame.lookVector * lengthOfRay)
        local rayResult, aimpoint = workspace:FindPartOnRayWithIgnoreList(cameraRay, {aimPointInd})
        --aimPointInd.CFrame = CFrame.new(aimpoint)

        aimpoint = hull.CFrame:pointToObjectSpace(aimpoint).unit    
        --local aimpoint = (aimpoint - hull.CFrame.p).unit
        local tan1 = (aimpoint.X)
        local tan2 = (aimpoint.Z)
        if tan1 <= 0 and tan2 <= 0 or tan1 >= 0 and tan2 <= 0 then
            azumithDif = -math.atan(tan1/tan2) * 180 / math.pi
        elseif tan1 >= 0 and tan2 >= 0 or tan1 <= 0 and tan2 >= 0 then
            azumithDif = 180-math.atan(tan1/tan2) * 180 / math.pi
        end
        turretHinge.TargetAngle = azumithDif
    end

Gun Setup function:

function gunSetup()
    if gunAzumithLimits[1] and gunAzumithLimits[2] then
        turretHinge.LimitsEnabled = true
        turretHinge.UpperAngle = gunAzumithLimits[1]
        turretHinge.LowerAngle = gunAzumithLimits[2]
    end
    if gunElevationLimits[1] and gunElevationLimits[2] then
        gunHinge.LimitsEnabled = true
        gunHinge.UpperAngle = gunAzumithLimits[1]
        gunHinge.LowerAngle = gunAzumithLimits[2]
    end 
    wait(5) --The 5s delay you can see in the video
    turretHinge.ActuatorType = 2
    turretHinge.AngularSpeed = 5 --Change later
    turretHinge.ServoMaxTorque = 1000000
end

EDIT: Nevermind, I've solved it. For future reference and anyone having the same problem, when you're working with custom characters with constraints, activating the actuator seems to reset network ownership of the connected parts. Simply create and call a remoteFunction that loops thru and sets network ownership after you activate the servos.

Answer this question