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
 

Re: hm, constructing 3D dragging.

Previous Thread :: Next Thread 
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
10 Jan 2013 02:08 PM
'ello there.

As I'm right now trying to find a way to make a "fake" rotate camera angle to replace the normal one (due to CameraMode == Scriptable), I find that it may not be as just-to-outfigurere as other stuff.


So, right now I've got these variables; initial angle, keeping the distance & on-dragged (we'll only have to make a vector for on-dragged (dragAngle).
Also, camera is a Camera, focusPart is the player's character's Head.


local angle = (camera.CoordinateFrame.p - focusPart.Position).unit
local distance = (camera.CoordinateFrame.p - focusPart.Position).Magnitude
local dragAngle = Vector3.new(0, 0, 0)


Going to see if I can find something meanwhile...
-As, a spider! Oh where?
Report Abuse
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
10 Jan 2013 02:11 PM
Idea (will this work?):

Generating a lookVector-thing from the camera's CoordinateFrame to the Mouse's Hit position?
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
10 Jan 2013 02:39 PM
"Generating a lookVector-thing from the camera's CoordinateFrame to the Mouse's Hit position?"

lookVector of CoordinateFrame would return cameras facing direction. You would use unit to get direction from camera to mouse:


(camera.CoordinateFrame.p - mouse.Hit.p).unit
Report Abuse
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
10 Jan 2013 02:59 PM
Hm, let's see... the result I've got right now is that you can drag the camera, yet it's flipping over in some cases (going through terrain, inversed Y coordinate, going kinda kapoooow when rotating ~360 degrees ect.)

Ok, tomorrow...
-As, moonwalkin' iz da new laifstyle. Bai.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
10 Jan 2013 03:31 PM
I could help.
Report Abuse
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
11 Jan 2013 02:56 AM
Okay, I'll post the script when I can. Gotta add :FindPartOnRay to block look-through glitch.


-As, not responsible for iPad correction misunderstanding.
Report Abuse
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
11 Jan 2013 07:33 AM
Ok, there we go. LocalScript, yes. Used to make us able to "tilt" the camera while still having the basic ROBLOX camera control. Adding zoom-stuff, I guess. Fixing intersect-glitch. Optimizing throttle. Trolling you. Mkai?

Script code (I love to make messy codes, I guess...):
---------------------------------------------------------------------------
function waitForChild(instance, name) if instance:FindFirstChild(name) then return instance:FindFirstChild(name) end
while true do instance.ChildAdded:wait() if instance:FindFirstChild(name) then return instance:FindFirstChild(name) end end end
function waitForProperty(instance, name) if instance[name] then return instance[name] end
while true do instance.Changed:wait() if instance[name] then return instance[name] end end end

function generateDrag(camera, mouse)
return (camera.CoordinateFrame.p - mouse.Hit.p).unit
end

function onCamera(camera, focusPart, mouse)
local angle = (camera.CoordinateFrame.p - focusPart.Position).unit
local distance = (camera.CoordinateFrame.p - focusPart.Position).Magnitude
local dragInit = generateDrag(camera, mouse)
local dragAngle = generateDrag(camera, mouse) * -1
local isDragging = false
local dragEvent = {}
dragEvent["2Down"] = mouse.Button2Down:connect(function() isDragging = true dragInit = generateDrag(camera, mouse) end)
dragEvent["2Up"] = mouse.Button2Up:connect(function() if distance > 0.2 then isDragging = false end end)
dragEvent["Move"] = mouse.Move:connect(function() if distance < 0.2 or isDragging then dragAngle = generateDrag(camera, mouse) end end)
while camera.CameraType == Enum.CameraType.Scriptable do
camera.CoordinateFrame = CFrame.new(focusPart.Position) * CFrame.new((angle + (dragAngle - dragInit)) * distance, Vector3.new(0, 0, 0)) wait(-1)
end end

local player = waitForProperty(game:service("Players"), "LocalPlayer")
local pCamera = waitForProperty(workspace, "CurrentCamera")
local pHead = waitForChild(waitForProperty(player, "Character"), "Head")
local pMouse = player:GetMouse()

pCamera.Changed:connect(function(prop) if prop == "CameraType" and pCamera.CameraType == Enum.CameraType.Scriptable then
onCamera(pCamera, pHead, pMouse) end end)
---------------------------------------------------------------------------


Back to work, let's add CustomFog, CustomTerrain & new properties to GUI & decal/texture objects,
-As
Report Abuse
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
11 Jan 2013 08:05 AM
---------------

A problem is that you can still move your mouse when not in FirstPersonMode.
I guess another problem is that there's miscalculation at some dragging points. I guess I'll have to focus more on the mouse's X & Y properties.
Report Abuse
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
11 Jan 2013 08:22 AM
Fixed a few glitches, obviously... It seems like CameraType.Scriptable (Camera) even overwrite CameraMode.LockFirstPerson (Player).

------------------------------------------------------------------------------------
function waitForChild(instance, name) if instance:FindFirstChild(name) then return instance:FindFirstChild(name) end
while true do instance.ChildAdded:wait() if instance:FindFirstChild(name) then return instance:FindFirstChild(name) end end end
function waitForProperty(instance, name) if instance[name] then return instance[name] end
while true do instance.Changed:wait() if instance[name] then return instance[name] end end end

function generateDrag(camera, mouse)
return (camera.CoordinateFrame.p - mouse.Hit.p).unit
end

function onCamera(player, camera, focusPart, mouse)
local angle = (camera.CoordinateFrame.p - focusPart.Position).unit
local distance = (camera.CoordinateFrame.p - focusPart.Position).Magnitude
local dragInit = generateDrag(camera, mouse)
local dragAngle = generateDrag(camera, mouse)
local isDragging = false
local dragEvent = {}
dragEvent["2Down"] = mouse.Button2Down:connect(function() isDragging = true dragInit,dragAngle=generateDrag(camera,mouse),generateDrag(camera,mouse) end)
dragEvent["2Up"] = mouse.Button2Up:connect(function() if distance > 0.2 then isDragging = false angle = angle + (dragAngle - dragInit)
dragInit,dragAngle=Vector3.new(0, 0, 0),Vector3.new(0, 0, 0) end end)
dragEvent["Move"] = mouse.Move:connect(function() if distance < 0.2 or isDragging then dragAngle = generateDrag(camera, mouse)
player.CameraMode = Enum.CameraMode.LockFirstPerson else player.CameraMode = Enum.CameraMode.Classic end end)
while camera.CameraType == Enum.CameraType.Scriptable do
camera.CoordinateFrame = CFrame.new(focusPart.Position) * CFrame.new((angle + (dragAngle - dragInit)) * distance, Vector3.new(0, 0, 0)) wait(-1)
end for k,_ in pairs(dragEvent) do if dragEvent[k] then pcall(function() dragEvent[k]:disconnect() dragEvent[k] = nil end) end end end

local pPlayer = waitForProperty(game:service("Players"), "LocalPlayer")
local pCamera = waitForProperty(workspace, "CurrentCamera")
local pHead = waitForChild(waitForProperty(pPlayer, "Character"), "Head")
local pMouse = pPlayer:GetMouse()

pCamera.Changed:connect(function(prop) if prop == "CameraType" and pCamera.CameraType == Enum.CameraType.Scriptable then
onCamera(pPlayer, pCamera, pHead, pMouse) end end)
------------------------------------------------------------------------------------
Report Abuse
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
12 Jan 2013 07:53 AM
Hm, I wonder... would it be fine just saying "Yes, this is what we can do. Just go get dizzy, we won't give you anymore controlzzzzzzzzz...." :/
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