generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Camera Follow Missile (Simple?)

Previous Thread :: Next Thread 
GuestCapone is not online. GuestCapone
Joined: 19 Oct 2012
Total Posts: 1928
22 Jan 2013 11:38 PM
Tried to edit the roblox RPG... I wanted to make your camera follow the missile.. I somewhat achieved that... Camera mode changes like I want it to when it fires/explodes.. However, I can't seem to figure out why the camera isn't following the missile...

Just in case you don't wish to read everything please skip to "CamPart" (Ctrl+F)

local Tool = script.Parent
local Launcher = Tool.Handle

local Rocket = Instance.new("Part")
Rocket.Locked = true
Rocket.BackSurface = 3
Rocket.BottomSurface = 3
Rocket.FrontSurface = 3
Rocket.LeftSurface = 3
Rocket.RightSurface = 3
Rocket.TopSurface = 3
Rocket.Size = Vector3.new(1, 2.5, 1)
Rocket.BrickColor = BrickColor.new(23)
Rocket.FormFactor = 3


local rocketMesh = Instance.new("SpecialMesh")
rocketMesh.MeshId = "http://www.roblox.com/asset/?id=31601976"
rocketMesh.TextureId = "http://www.roblox.com/asset/?id=31601599"
rocketMesh.Parent = Rocket

local debris = game:GetService("Debris")

local swooshSound
local explosionSound

local vCharacter
local vPlayer
--[[
s = script.Parent.Camera:Clone()
s.Parent = Rocket
--]]
function blow(hit, missile)
if missile == nil then return end
if swooshSound then swooshSound:stop() end
explosion = Instance.new("Explosion")
explosion.Position = missile.Position
-- find instigator tag
local creator = missile:FindFirstChild("creator")
explosion.Hit:connect(function(part, distance) onPlayerBlownUp(part, distance, creator) end)
explosion.Parent = game.Workspace
if explosionSound then explosionSound:Play() end
wait(.1)
if missile then missile:Remove() end
camera.CameraType = "Custom"
end

function onPlayerBlownUp(part, distance, creator)
if part.Name == "Head" or part.Name == "Torso" then
local humanoid = part.Parent.Humanoid
tagHumanoid(humanoid, creator)
end
end

function tagHumanoid(humanoid, creator)
-- tag does not need to expire if all explosions lethal
if creator ~= nil then
local new_tag = creator:clone()
new_tag.Parent = humanoid
end
end

function fire(vTarget)
local vCharacter = Tool.Parent
local vHandle = Tool:findFirstChild("Handle")
if vHandle == nil then
print("Handle not found")
return
end
local direction = vTarget - vHandle.Position
direction = computeDirection(direction)
local missile = Rocket:clone()
local pos = vHandle.Position + (direction * 10.0)
missile.CFrame = CFrame.new(pos, pos + direction) * CFrame.Angles(math.pi/2, 0, 0)
------------------------------Camera Follow Missile here.
player = game.Players.LocalPlayer
camera = workspace.CurrentCamera
camera.CameraType = 2
camera.CoordinateFrame = missile.CFrame
camera.Focus = missile.CFrame + missile.CFrame.lookVector --* 300
------------------------------Camera Follow Missile here.
local creator_tag = Instance.new("ObjectValue")

local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)

if vPlayer == nil then
print("Player not found")
else
if (vPlayer.Neutral == false) then -- nice touch
missile.BrickColor = vPlayer.TeamColor
end
end

local floatForce = Instance.new("BodyForce")
floatForce.force = Vector3.new(0, missile:GetMass() * 196.1, 0.0)
floatForce.Parent = missile

missile.Velocity = direction * 20.0

creator_tag.Value = vPlayer
creator_tag.Name = "creator"
creator_tag.Parent = missile

missile.Parent = game.Workspace

if swooshSound then swooshSound:Play() end



missile.Touched:connect(function(hit) blow(hit, missile) end)

debris:AddItem(missile, 100.0)
end

function computeDirection(vec)
local lenSquared = vec.magnitude * vec.magnitude
local invSqrt = 1 / math.sqrt(lenSquared)
return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

Tool.Enabled = true
function onActivated()
if not Tool.Enabled then
return
end

Tool.Enabled = false

local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
print("Humanoid not found")
return
end

swooshSound = Launcher:FindFirstChild("Swoosh")
explosionSound = Launcher:FindFirstChild("Explosion")

local targetPos = humanoid.TargetPoint

fire(targetPos)

wait(7)

Tool.Enabled = true
end


script.Parent.Activated:connect(onActivated)
--Must be in a LocalScript.


CamPart snippet.


player = game.Players.LocalPlayer
camera = workspace.CurrentCamera
camera.CameraType = 2
camera.CoordinateFrame = missile.CFrame
camera.Focus = missile.CFrame + missile.CFrame.lookVector --* 300

I've been able to get the camera mode to change upon firing/exploding. But I'm not able to get it to follow the part, is this because I've forgot to put in a line? Or is the snippet in the wrong spot?
Report Abuse
jrf2112 is not online. jrf2112
Joined: 29 Jun 2008
Total Posts: 3354
22 Jan 2013 11:40 PM
Camera Subject?
Report Abuse
jrf2112 is not online. jrf2112
Joined: 29 Jun 2008
Total Posts: 3354
22 Jan 2013 11:41 PM
Set your camera type to 1. lol
Report Abuse
GuestCapone is not online. GuestCapone
Joined: 19 Oct 2012
Total Posts: 1928
22 Jan 2013 11:45 PM
lol, well now I know the camera is focusing on the players head...
Any reason why its focusing on the head and not the missile?
Report Abuse
jrf2112 is not online. jrf2112
Joined: 29 Jun 2008
Total Posts: 3354
22 Jan 2013 11:48 PM
It can't look at the missile while it's attached to the head.
Report Abuse
GuestCapone is not online. GuestCapone
Joined: 19 Oct 2012
Total Posts: 1928
23 Jan 2013 11:04 AM
Camera subject... Needed that.

local Tool = script.Parent
local Launcher = Tool.Handle
local player = game.Players.LocalPlayer
local LocalRocketName = player.Name

local Rocket = Instance.new("Part")
Rocket.Locked = true
Rocket.BackSurface = 3
Rocket.BottomSurface = 3
Rocket.FrontSurface = 3
Rocket.LeftSurface = 3
Rocket.RightSurface = 3
Rocket.TopSurface = 3
Rocket.Size = Vector3.new(1, 2.5, 1)
Rocket.BrickColor = BrickColor.new(23)
Rocket.FormFactor = 3
Rocket.Name = LocalRocketName


local rocketMesh = Instance.new("SpecialMesh")
rocketMesh.MeshId = "http://www.roblox.com/asset/?id=31601976"
rocketMesh.TextureId = "http://www.roblox.com/asset/?id=31601599"
rocketMesh.Parent = Rocket

local debris = game:GetService("Debris")

local swooshSound
local explosionSound

local vCharacter
local vPlayer
--[[
s = script.Parent.Camera:Clone()
s.Parent = Rocket
--]]
function blow(hit, missile)
if missile == nil then return end
if swooshSound then swooshSound:stop() end
explosion = Instance.new("Explosion")
explosion.Position = missile.Position
-- find instigator tag
local creator = missile:FindFirstChild("creator")
explosion.Hit:connect(function(part, distance) onPlayerBlownUp(part, distance, creator) end)
explosion.Parent = game.Workspace
if explosionSound then explosionSound:Play() end
wait(.1)
if missile then missile:Remove() end
camera.CameraType = 5
camera.CameraSubject = game.Players.LocalPlayer.Character.Head
end

function onPlayerBlownUp(part, distance, creator)
if part.Name == "Head" or part.Name == "Torso" then
local humanoid = part.Parent.Humanoid
tagHumanoid(humanoid, creator)
end
end

function tagHumanoid(humanoid, creator)
-- tag does not need to expire if all explosions lethal
if creator ~= nil then
local new_tag = creator:clone()
new_tag.Parent = humanoid
end
end

function fire(vTarget)
local vCharacter = Tool.Parent
local vHandle = Tool:findFirstChild("Handle")
if vHandle == nil then
print("Handle not found")
return
end
local direction = vTarget - vHandle.Position
direction = computeDirection(direction)
local missile = Rocket:clone()
local pos = vHandle.Position + (direction * 10.0)
missile.CFrame = CFrame.new(pos, pos + direction) * CFrame.Angles(math.pi/2, 0, 0)
------------------------------Camera Follow Missile here.
camera = workspace.CurrentCamera
camera.CameraType = 1
camera.CoordinateFrame = missile.CFrame
camera.Focus = missile.CFrame + missile.CFrame.lookVector --* 300
camera.CameraSubject = missile
------------------------------Camera Follow Missile here.
local creator_tag = Instance.new("ObjectValue")

local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)

if vPlayer == nil then
print("Player not found")
else
if (vPlayer.Neutral == false) then -- nice touch
missile.BrickColor = vPlayer.TeamColor
end
end

local floatForce = Instance.new("BodyForce")
floatForce.force = Vector3.new(0, missile:GetMass() * 196.1, 0.0)
floatForce.Parent = missile

missile.Velocity = direction * 20.0

creator_tag.Value = vPlayer
creator_tag.Name = "creator"
creator_tag.Parent = missile

missile.Parent = game.Workspace

if swooshSound then swooshSound:Play() end



missile.Touched:connect(function(hit) blow(hit, missile) end)

debris:AddItem(missile, 100.0)
end

function computeDirection(vec)
local lenSquared = vec.magnitude * vec.magnitude
local invSqrt = 1 / math.sqrt(lenSquared)
return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

Tool.Enabled = true
function onActivated()
if not Tool.Enabled then
return
end

Tool.Enabled = false

local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
print("Humanoid not found")
return
end

swooshSound = Launcher:FindFirstChild("Swoosh")
explosionSound = Launcher:FindFirstChild("Explosion")

local targetPos = humanoid.TargetPoint

fire(targetPos)

wait(7)

Tool.Enabled = true
end


script.Parent.Activated:connect(onActivated)


Works.. Just that the camera type isn't returning back to classic (5), camera subject does, just not camera type.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image