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 » Scripters
Home Search
 

Re: lookVector to rotation?

Previous Thread :: Next Thread 
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 06:15 PM
title.
i need to add 45 to the y rotation but my game uses look vector. and when I change the rotation it simply glitches back and fourth. (because the script repeates every 1/60th of a second
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 06:36 PM
help
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 06:39 PM
Post code.

Based on the title only, you can't: the look vector is normal to a plane (x, y axes). A lookVector corresponds to an infinite number of rotations (just as long as the local x and y axes lie within a plane normal to said lookvector).
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 06:42 PM
local CONSTANT_Y = 1.5;

local function cleanPosition(v3)
--Ensures that the vector3 will return with actual numbers.
local rv = Vector3.new()

if tonumber(v3.x) ~= nil then
rv = rv + Vector3.new(v3.x,0,0);
end
if tonumber(v3.z) ~= nil then
rv = rv + Vector3.new(0,0,v3.z);
end

return rv + Vector3.new(0,CONSTANT_Y,0);
end

-- This for some reason is faster than using the raycasting functions??

function getMouseIntersection(cam,m)
local ray = m.UnitRay.Unit;
if math.abs(ray.Direction.y) > 10000 or (ray.Direction.y ~= ray.Direction.y) then
return cleanPosition(cam.CoordinateFrame.p);
end
local nphi = (CONSTANT_Y - ray.Origin.y) / (ray.Direction.y);
local intersection = ray.Origin + ray.Direction * nphi;
return cleanPosition(intersection);
end

local p = getMouseIntersection(game.Workspace.CurrentCamera, mouse) -- lookvector
local p2 = Vector3.new(p.x, 1.5, p.z)
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 06:51 PM
Let me be more specific.

Explain what your code is doing; what is p and p2?

For instance, what is this?
local ray = m.UnitRay.Unit; --You are normalize a ray that is already normalized?
if math.abs(ray.Direction.y) > 10000 or (ray.Direction.y ~= ray.Direction.y) then
--// Because the ray is normalized Direction.Y will always be <= 1 and won't ray.Direction.Y ALWAYS be equal to ray.Direction.y?
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 06:53 PM
tbh, this part you are asking for isn't my script.
I was having a problem and he gave me this to fix it.
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 06:55 PM
Let's take it from the top.

For now, my questions are:
What is the purpose of the whole script?
What are p and p2 and how are they used later?
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 06:57 PM
This part of the script is to prevent the spawning part from spawning at y -(infinite).
p2 basicly makes the brick so it can't look up or down. (by making it look on the 2d plane)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
24 Jul 2015 06:58 PM
Add 5000 to one of those values in there and it will work. Trust me, I know what I'm doing.


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 06:59 PM
"one of those values" and that value is?
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 07:07 PM
He's being a troll. Ignore him.

I'm trying to help you out here, but it's like pulling teeth.

What is the WHOLE script supposed to do? (not just this part)
Explain the problem is DETAIL.

From what I have gathered, you are trying to spawn something somehow and without being able to see how you are using p2 (which I gather is the lookvector in question???) I can't tell you why it's flickering.

Do the above, and post the WHOLE script. Please.
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 07:09 PM
The point of my script is to move a fish around and eat other players and food.
local CONSTANT_Y = 1.5;

local function cleanPosition(v3)
--Ensures that the vector3 will return with actual numbers.
local rv = Vector3.new()

if tonumber(v3.x) ~= nil then
rv = rv + Vector3.new(v3.x,0,0);
end
if tonumber(v3.z) ~= nil then
rv = rv + Vector3.new(0,0,v3.z);
end

return rv + Vector3.new(0,CONSTANT_Y,0);
end

-- This for some reason is faster than using the raycasting functions??

function getMouseIntersection(cam,m)
local ray = m.UnitRay.Unit;
if math.abs(ray.Direction.y) > 10000 or (ray.Direction.y ~= ray.Direction.y) then
return cleanPosition(cam.CoordinateFrame.p);
end
local nphi = (CONSTANT_Y - ray.Origin.y) / (ray.Direction.y);
local intersection = ray.Origin + ray.Direction * nphi;
return cleanPosition(intersection);
end
------------------------------------------------------------------------------------

function GetTouching(Part)
local Touching = {}
if Part:IsA("BasePart") then
local PartCollides = Part.CanCollide
Part.CanCollide = true
for _, OtherPart in pairs(Part:GetTouchingParts()) do
if OtherPart.Parent == game.Workspace.Food or OtherPart.Parent == game.Workspace.Players then
Touching = OtherPart
end
end
Part.CanCollide = PartCollides
end
return Touching
end

game.Workspace:WaitForChild(game.Players.LocalPlayer.Name):Destroy()
function newPart()
wait(3)
--part = Instance.new("Part", game.Workspace.Players)
part = game.ServerStorage.Union:Clone()
part.Parent = game.Workspace.Players
part.Position = Vector3.new(0, CONSTANT_Y, 0)
part.Anchored = true
part.Name = game.Players.LocalPlayer.Name
--part.FormFactor = "Custom"
mass = Instance.new("NumberValue", part)
mass.Name = "mass"
mass.Value = 50 --math.random(50, 75)
end
newPart()
local mouse = game.Players.LocalPlayer:GetMouse()
local base = workspace.Baseplate

while wait(1/60) do
--game:GetService("RunService").RenderStepped:connect(function()
if part.Parent == nil then
newPart()
end
if GetTouching(part).Parent == game.Workspace.Food then
GetTouching(part):Destroy()
mass.Value = mass.Value + 1
local food = Instance.new("Part", game.Workspace.Food)
food.Name = "Food"
food.Anchored = true
--food.CanCollide = false
food.FormFactor = "Custom"
food.Size = Vector3.new(1, .2, 1)
food.TopSurface = "Smooth"
food.BottomSurface = "Smooth"
food.BrickColor = BrickColor.new(21)
food.Position = Vector3.new(math.random(-base.Size.X-base.Size.X/2,base.Size.X-base.Size.X/2),1.5,math.random(-base.Size.Z-base.Size.Z/2,base.Size.Z-base.Size.Z/2))
elseif GetTouching(part).Parent == game.Workspace.Players then
if GetTouching(part).mass.Value*(11/10) < mass.Value then
mass.Value = mass.Value + (GetTouching(part).mass.Value)
GetTouching(part):Destroy()
end
end
if mass.Value >= 10001 then
mass.Value = 10000
elseif mass.Value >= 1000 then
mass.Value = mass.Value - ((1.01^((mass.Value-1000)/60))/10)
end
local pos = part.Position
local p = getMouseIntersection(game.Workspace.CurrentCamera, mouse) -- lookvector
local p2 = Vector3.new(p.x, 1.5, p.z)
local rot = part.Rotation
part.CanCollide = false
part.Size = Vector3.new(mass.Value/50,mass.Value/100,mass.Value/50)
part.CanCollide = true
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(pos+Vector3.new(0, mass.Value/15+20))*CFrame.Angles(math.rad(-89.9), 0, math.rad(-90))
if (p - pos).Magnitude <= 1000 then
if math.floor(part.Position.X) ~= math.floor(p.x) and math.floor(part.Position.Z) ~= math.floor(p.z) then
part.CFrame = CFrame.new(part.Position, p2)
end
if math.floor(part.Position.X) < workspace.Baseplate.Size.X/2 then
if math.floor(part.Position.X) > -(workspace.Baseplate.Size.X/2) then
if math.floor(part.Position.Z) < workspace.Baseplate.Size.Z/2 then
if math.floor(part.Position.Z) > -(workspace.Baseplate.Size.Z/2) then
part.CFrame = part.CFrame * CFrame.new(0, 0, ((1/205)*mass.Value-50)/25)
---(math.pow(3000,3.8/mass.Value)-1)
else
part.CFrame = CFrame.new(part.Position.x, CONSTANT_Y, part.Position.z + 0.05)
part.CFrame = CFrame.new(part.Position, p2)
end
else
part.CFrame = CFrame.new(part.Position.x, CONSTANT_Y, part.Position.z - 0.05)
part.CFrame = CFrame.new(part.Position, p2)
end
else
part.CFrame = CFrame.new(part.Position.x + 0.05, CONSTANT_Y, part.Position.z)
part.CFrame = CFrame.new(part.Position, p2)
end
else
part.CFrame = CFrame.new(part.Position.x - 0.05, CONSTANT_Y, part.Position.z)
part.CFrame = CFrame.new(part.Position, p2)
end
rot = Vector3.new(rot.X, rot.Y - 45, rot.Z)
--part.Rotation = rot
end
end--)
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 07:10 PM
Thank, that I can work with. Give me a few minutes to debug. Thank you for your patience (and I apologize for losing mine).
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 07:11 PM
It's fine. :)
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 08:46 PM
That wasn't fun.

local CONSTANT_Y = 1.5;
local ROT_Y = 45
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local base = workspace.Baseplate;
(player.Character or player.CharacterAdded:Wait()):Destroy()

function GetTouching(Part)
local Touching = {}
if Part:IsA("BasePart") then
local PartCollides = Part.CanCollide
Part.CanCollide = true
for _, OtherPart in pairs(Part:GetTouchingParts()) do
if OtherPart.Parent == game.Workspace.Food or OtherPart.Parent == workspace.Players then
Touching = OtherPart
end
end
Part.CanCollide = PartCollides
end
return Touching
end
function getlookVector()
local smallestDim = mouse.ViewSizeX > mouse.ViewSizeY and mouse.ViewSizeY or mouse.ViewSizeX
local lookVector = Vector3.new(mouse.Y/smallestDim, 0, mouse.X/smallestDim) - Vector3.new(.5*mouse.ViewSizeY/smallestDim, 0, .5*mouse.ViewSizeX/smallestDim)
lookVector = lookVector*Vector3.new(-2,0,2)
return lookVector.magnitude <.2 and Vector3.new() or (lookVector.magnitude > 1 and lookVector.unit) or lookVector
end
--game.Workspace:WaitForChild(game.Players.LocalPlayer.Name):Destroy()
function newPart()
wait(3)
part = (game.ServerStorage:FindFirstChild("Union") or Instance.new("Part")):Clone() --// If union doesn't exist, use a standard part. I don't have access to your Union obj, so this will do
part.Parent = workspace.Players
part.Position = Vector3.new(0, CONSTANT_Y, 0)
part.Anchored = true
part.Name = player.Name
--part.FormFactor = "Custom"
mass = Instance.new("NumberValue", part)
mass.Name = "mass"
mass.Value = 50 --math.random(50, 75)
end
newPart()

while true do
if not part.Parent then
newPart()
end
local tock = tick()
game:GetService("RunService").RenderStepped:wait()
local dt = tick() - tock
local touchedPart = GetTouching(part)
if touchedPart.Parent == workspace.Food then
touchedPart:Destroy()
mass.Value = mass.Value + 1
local food = Instance.new("Part", game.Workspace.Food)
food.Name = "Food"
food.Anchored = true
--food.CanCollide = false
food.FormFactor = "Custom"
food.Size = Vector3.new(1, .2, 1)
food.TopSurface = "Smooth"
food.BottomSurface = "Smooth"
food.BrickColor = BrickColor.new(21)
food.Position = Vector3.new(math.random(-base.Size.X-base.Size.X/2,base.Size.X-base.Size.X/2),1.5,math.random(-base.Size.Z-base.Size.Z/2,base.Size.Z-base.Size.Z/2))
elseif touchedPart.Parent == workspace.Players then
if touchedPart.mass.Value*1.1 < mass.Value then
mass.Value = mass.Value + (touchedPart.mass.Value)
touchedPart:Destroy()
end
end
if mass.Value >= 10001 then
mass.Value = 10000
elseif mass.Value >= 1000 then
mass.Value = mass.Value - ((1.01^((mass.Value-1000)/60))/10)
end
local pos = part.Position
local p = getlookVector() -- lookvector
local p2 = Vector3.new(p.x, 1.5, p.z)
local rot = part.Rotation
part.CanCollide = false
part.Size = Vector3.new(.02,.01,.02)*mass.Value
part.CanCollide = true
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CoordinateFrame = CFrame.new(pos+Vector3.new(0, mass.Value/15+20), pos+Vector3.new(1, 0, 0))--*CFrame.Angles(math.rad(-89.9), 0, math.rad(-90))
local cframe
if p.magnitude ~= 0 then
cframe = CFrame.new(pos, pos+p.unit)* --//set lookVector
CFrame.new(0, 0, ((1/205)*mass.Value-50)/25*60*dt*p.magnitude)* --// move fish; I standardized speed relative to frame rate (*60*dt where dt roughly 1/60) and made speed relative to cursor movement from screen center
CFrame.Angles(0, math.rad(ROT_Y), 0) --// change fishie's orientation
else
cframe = part.CFrame
end
--// keep fishie in bounds.
--// After moving fishie I make sure he is still on the baseplate
pos = cframe.p/(workspace.Baseplate.Size/2) -- setup ratio,
pos = Vector3.new(
math.abs(pos.X)>1 and pos.X/math.abs(pos.X) or pos.X,
--[[
equivalent to
local x =
if math.abs(pos.X) > 1 then --// fishie is out of bounds
x = pos.X/math.abs(pos.X) --// standardize x to +-1, keeing the sign
else
x = pos.X --//fishie is in bounds and I don't have to clamp his position
end
...
pos = Vector3.new(x, y, z)
--]]
math.abs(pos.Y)>1 and pos.Y/math.abs(pos.Y) or pos.Y,
math.abs(pos.Z)>1 and pos.Z/math.abs(pos.Z) or pos.Z
)*workspace.Baseplate.Size/2
part.CFrame = (cframe - cframe.p + pos) --// replacing position associated to cframe with corrected pos
end
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 10:13 PM
The fish seems to be oddly moving back and fourth and is going very slow. hm.
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 10:21 PM
try this:


local CONSTANT_Y = 1.5;
local ROT_Y = 45
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local base = workspace.Baseplate;
(player.Character or player.CharacterAdded:Wait()):Destroy()

function GetTouching(Part)
local Touching = {}
if Part:IsA("BasePart") then
local PartCollides = Part.CanCollide
Part.CanCollide = true
for _, OtherPart in pairs(Part:GetTouchingParts()) do
if OtherPart.Parent == game.Workspace.Food or OtherPart.Parent == workspace.Players then
Touching = OtherPart
end
end
Part.CanCollide = PartCollides
end
return Touching
end
function getlookVector()
local smallestDim = mouse.ViewSizeX > mouse.ViewSizeY and mouse.ViewSizeY or mouse.ViewSizeX
local lookVector = Vector3.new(mouse.Y/smallestDim, 0, mouse.X/smallestDim) - Vector3.new(.5*mouse.ViewSizeY/smallestDim, 0, .5*mouse.ViewSizeX/smallestDim)
lookVector = lookVector*Vector3.new(-2,0,2)
return lookVector.magnitude <.2 and Vector3.new() or (lookVector.magnitude > 1 and lookVector.unit) or lookVector
end
--game.Workspace:WaitForChild(game.Players.LocalPlayer.Name):Destroy()
function newPart()
wait(3)
part = (game.ReplicatedStorage:FindFirstChild("Union") or Instance.new("Part")):Clone() --// If union doesn't exist, use a standard part. I don't have access to your Union obj, so this will do
part.Parent = workspace.Players
part.Position = Vector3.new(0, CONSTANT_Y, 0)
part.Anchored = true
part.Name = player.Name
--part.FormFactor = "Custom"
mass = Instance.new("NumberValue", part)
mass.Name = "mass"
mass.Value = 50 --math.random(50, 75)
end
newPart()

while true do
if not part.Parent then
newPart()
end
local tock = tick()
game:GetService("RunService").RenderStepped:wait()
local dt = tick() - tock
local touchedPart = GetTouching(part)
if touchedPart.Parent == workspace.Food then
touchedPart:Destroy()
mass.Value = mass.Value + 1
local food = Instance.new("Part", game.Workspace.Food)
food.Name = "Food"
food.Anchored = true
--food.CanCollide = false
food.FormFactor = "Custom"
food.Size = Vector3.new(1, .2, 1)
food.TopSurface = "Smooth"
food.BottomSurface = "Smooth"
food.BrickColor = BrickColor.new(21)
food.Position = Vector3.new(math.random(-base.Size.X-base.Size.X/2,base.Size.X-base.Size.X/2),1.5,math.random(-base.Size.Z-base.Size.Z/2,base.Size.Z-base.Size.Z/2))
elseif touchedPart.Parent == workspace.Players then
if touchedPart.mass.Value*1.1 < mass.Value then
mass.Value = mass.Value + (touchedPart.mass.Value)
touchedPart:Destroy()
end
end
if mass.Value >= 10001 then
mass.Value = 10000
elseif mass.Value >= 1000 then
mass.Value = mass.Value - ((1.01^((mass.Value-1000)/60))/10)
end
local pos = part.Position
local p = getlookVector() -- lookvector
local p2 = Vector3.new(p.x, 1.5, p.z)
local rot = part.Rotation
part.CanCollide = false
part.Size = Vector3.new(.02,.01,.02)*mass.Value
part.CanCollide = true
local cframe
if p.magnitude ~= 0 then
cframe = CFrame.new(pos, pos+p.unit)* --//set lookVector
CFrame.new(0, 0, ((1/205)*mass.Value-50)/25*60*dt)
--CFrame.new(0, 0, ((1/205)*mass.Value-50)/25*60*dt*p.magnitude)* --// move fish; I standardized speed relative to frame rate (*60*dt where dt roughly 1/60) and made speed relative to cursor movement from screen center
CFrame.Angles(0, math.rad(ROT_Y), 0) --// change fishie's orientation
else
cframe = part.CFrame
end
--// keep fishie in bounds.
--// After moving fishie I make sure he is still on the baseplate
pos = cframe.p/(workspace.Baseplate.Size/2) -- setup ratio,
pos = Vector3.new(
math.abs(pos.X)>1 and pos.X/math.abs(pos.X) or pos.X,
--[[
equivalent to
local x =
if math.abs(pos.X) > 1 then --// fishie is out of bounds
x = pos.X/math.abs(pos.X) --// standardize x to +-1, keeing the sign
else
x = pos.X --//fishie is in bounds and I don't have to clamp his position
end
...
pos = Vector3.new(x, y, z)
--]]
math.abs(pos.Y)>1 and pos.Y/math.abs(pos.Y) or pos.Y,
math.abs(pos.Z)>1 and pos.Z/math.abs(pos.Z) or pos.Z
)*workspace.Baseplate.Size/2
part.CFrame = (cframe - cframe.p + pos) --// replacing position associated to cframe with corrected pos
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CoordinateFrame = CFrame.new(part.Position+Vector3.new(0, mass.Value/15+20), pos+Vector3.new(1, 0, 0))--*CFrame.Angles(math.rad(-89.9), 0, math.rad(-90))
end
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 10:27 PM
your script never seems to work in studio test mode. It always crashes. I believe it's because of the method for deleting the character
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 10:30 PM
Works fine in my studio O_o
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 10:32 PM
Hm, also the player increases in size spontaniopusly and not how my original script did it.
also, the fish is gone :O
But I like how when you touch the border it actualy works great.
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 10:33 PM
the fish is gone because you changed the stoarage to replicated (sorry i just noticed)
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 10:40 PM
Sorry, it appeared to just be a one time thing.
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
24 Jul 2015 10:42 PM
So now it all works?

By the way, you can't access ServerStorage from a local script in online mode, you should move the fish to replicated.
Report Abuse
Gladii is not online. Gladii
Joined: 10 Mar 2012
Total Posts: 1713
24 Jul 2015 10:44 PM
Thanks, I'll send you a PM if anything goes wroung!
Thanks for being a massive help!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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