I appreciate all the help. When you say make them as replicated, you just mean make them global, and for the others, appending LOCAL to the end, right?
To make things simpler, I’m sticking as close to the Sample as possible to figure out the vehicle.
function HandleClientConnected(eventType, eventData)
PlaySound(fxConnect,1)
-- When a client connects, assign to scene to begin scene replication
local newConnection = eventData["Connection"]:GetPtr("Connection")
newConnection.scene = scene_
-- Then create a controllable object for that client
local newObject = CreateControllableObject()
local newClient = {}
newClient.connection = newConnection
newClient.object = newObject
table.insert(clients, newClient)
-- Finally send the object's node ID using a remote event
local remoteEventData = VariantMap()
remoteEventData["ID"] = newObject.ID
newConnection:SendRemoteEvent("ClientObjectID", true, remoteEventData)
end
function CreateControllableObject()
-- Create the scene node & visual representation. This will be a replicated object
local ballNode = scene_:CreateChild("Ball")
ballNode.position = Vector3(Random(40.0) - 20.0, 5.0, Random(40.0) - 20.0)
ballNode:SetScale(0.5)
local ballObject = ballNode:CreateComponent("StaticModel")
ballObject.model = cache:GetResource("Model", "Models/Sphere.mdl")
ballObject.material = cache:GetResource("Material", "Materials/StoneSmall.xml")
local raycastVehicle=ballNode:CreateComponent("RaycastVehicle", LOCAL)
-- Create the physics components
local body = ballNode:CreateComponent("RigidBody")
body.mass = 1.0
body.friction = 1.0
-- In addition to friction, use motion damping so that the ball can not accelerate limitlessly
body.linearDamping = 0.5
body.angularDamping = 0.5
local shape = ballNode:CreateComponent("CollisionShape")
shape:SetSphere(1.0)
return ballNode
end
So when a client connects, the server creates a controllable object for them. Clients send in controls and the server loops through these objects and applies those controls accordingly. As soon as I add the raycast vehicle component, whether local or not, I get client crashing.
Unless I need to do the raycast vehicle component creation elsewhere? I assume that the server is creating these controllable objects, and so they are all being replicated?
EDIT: As a test, I did the following under the connect function, which should only be used by each client…
function HandleConnect(eventType, eventData)
PlaySound(fxConnect,1)
local address = textEdit.text
if address == "" then
address = "localhost" -- Use localhost to connect if nothing else specified
end
-- Connect to server, specify scene to use as a client for replication
clientObjectID = 0 -- Reset own object ID from possible previous connection
network:Connect(address, SERVER_PORT, scene_)
UpdateButtons()
test = scene_:CreateChild("test")
local raycastVehicle = test:CreateComponent("RaycastVehicle", LOCAL)
end
Same thing.