Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- RC CAR SCRIPT BY MARKIMUS
- http://steamcommunity.com/id/markipie/
- --]]
- -- Swap these values if the model you're using is moving sideways.
- Dir = {Forward = "z", Side = "x"}
- RCCar = true
- -- Changes whether the vehicle cares about touching the floor.
- WheelsMustTouchGround = false
- AccelerationSpeed = 1.2
- MoveMax = 10
- TurnSpeed = 2.1
- -- Controls which scripting buttons move the vehicle forwards, backwards, left & right.
- Indexes = {}
- Indexes[8] = "Forwards"
- Indexes[4] = "Left"
- Indexes[5] = "Backwards"
- Indexes[6] = "Right"
- -- These should not be changed.
- Movement = {}
- Movement.Forwards = false
- Movement.Right = false
- Movement.Backwards = false
- Movement.Left = false
- function round(n, dp)
- return math.floor(n*(dp*10)+0.5)/(dp*10)
- end
- function getGlobalForce(vector)
- local local_pos = self:positionToWorld(vector)
- local my_pos = self:getPosition()
- local new_force = {x=local_pos.x - my_pos.x, y=local_pos.y - my_pos.y, z=local_pos.z - my_pos.z}
- return new_force
- end
- function wheelsTouchingGround()
- if WheelsMustTouchGround == false then
- return true
- end
- local c = {}
- c.Direction = {0, -1, 0}
- c.type = 1
- c.max_distance = 0.2
- c.origin = self:getPosition()
- local results = Physics.cast(c)
- local my_pos = self:getPosition()
- for _, hit in pairs(results) do
- if hit.hit_object ~= self then
- return true
- end
- end
- return false
- end
- function fixedUpdate()
- if (Movement.Forwards == true or Movement.Backwards == true or Movement.Left == true or Movement.Right == true) and wheelsTouchingGround() then
- if Movement.Forwards == true or Movement.Backwards == true then
- local vel = self.getVelocity()
- if (math.abs(vel.x) + math.abs(vel.z)) < MoveMax then
- local add_force = {x=0, y=0, z=0}
- if Movement.Forwards == true then
- add_force[Dir.Forward] = add_force[Dir.Forward] + AccelerationSpeed
- end
- if Movement.Backwards == true then
- add_force[Dir.Forward] = add_force[Dir.Forward] - AccelerationSpeed
- end
- self:addForce(getGlobalForce(add_force), 4)
- end
- end
- if Movement.Left == true or Movement.Right == true then
- local my_torque = {x=0, y=0, z=0}
- if Movement.Left == true then
- my_torque.y = my_torque.y - TurnSpeed
- end
- if Movement.Right == true then
- my_torque.y = my_torque.y + TurnSpeed
- end
- self:setAngularVelocity(my_torque)
- end
- end
- end
- function inRange(num1, num2, range)
- if num1 >= num2 - range and num1 <= num2 + range then return true end
- return false
- end
- function tintSame(tint1, tint2)
- local range = 0.05
- if inRange(tint1.r, tint2.r, range) and inRange(tint1.g, tint2.g, range) and inRange(tint1.b, tint2.b, range) then
- return true
- end
- return false
- end
- function isOwner(my_col)
- for _, col in pairs(getSeatedPlayers()) do
- if self:getDescription() == col then
- if my_col == col then
- return true
- end
- return false
- end
- end
- if tintSame(stringColorToRGB(my_col), self:getColorTint()) then
- return true
- end
- return false
- end
- function onScriptingButtonDown(index, player_colour)
- if Indexes[index] ~= nil and isOwner(player_colour) then
- Movement[Indexes[index]] = true
- end
- end
- function onScriptingButtonUp(index, player_colour)
- if Indexes[index] ~= nil and isOwner(player_colour) then
- Movement[Indexes[index]] = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement