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: Help with a VERY complicated Vector3 equation.

Previous Thread :: Next Thread 
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
21 Apr 2014 01:29 PM
I'm trying to work out how you would get the top right corner of a randomly sized Z axis part, apply a random Z CFrame rotation from 135 - 160 to it, and minus the lookVector Y of the part to make it join infinitely like this:

_ _
\_/ \
\
\_
\

Here's my failed attempt at it:

--
if doneFirstPartYet == 0 then
p.CFrame = CFrame.new(startPosX + startPosX/2, startPosY - startPosY/2, startPosZ)*CFrame.Angles(0, 0, math.random(135,160))
elseif doneFirstPartYet == 1 then
local lastPartName = "SnowPart"..PartNumber - 1
local lastPart = lSlope:findFirstChild(lastPartName, true)
local lastPartLookVectorX = lastPart.CFrame.lookVector.X
local lastPartLookVectorY = lastPart.CFrame.lookVector.Y
local lastPartLookVectorZ = lastPart.CFrame.lookVector.Z
local lastPartPosX = lastPart.Position.X + lastPart.Size.X --------------->
local lastPartPosY = lastPart.Position.Y + lastPart.Size.Y - lastPartLookVectorY --> All of these mean the top right corner of the last part
local lastPartPosZ = lastPart.Position.Z -------------------------->
p.CFrame = CFrame.new(lastPartPosX, lastPartPosY, lastPartPosZ)*CFrame.Angles(0, 0, math.random(135,160))
end
--

I've been testing different ways of adding the size X of the part to the position X to position it the correct distance to the right, but I can't find a way to do it.

I'm sure SOMEBODY can figure this out, so thanks if you try to help me! :D If you need me to explain in better detail, let me know.
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
21 Apr 2014 01:30 PM
...I meant join infinitely like this :

_/`\_

but more down...
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
21 Apr 2014 01:34 PM
Your picture doesn't do much to explain what you want. Make a simple picture with paint(Or some similar program) then upload that image to prntscr and post a link here.
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
21 Apr 2014 01:36 PM
Ok jetta good idea I'll try to explain it with a screenshot of what I mean :>
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
21 Apr 2014 01:40 PM
http://postimg.org/image/a8suk8cvt/

I want it to generate a slope sort of like that, it's 2 dimensional.
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
21 Apr 2014 01:57 PM
Bump
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
21 Apr 2014 03:17 PM
Bump

If you need even more detail, let me know.
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
21 Apr 2014 03:48 PM
I'm a bit confused, but i'm sure it's not difficult. Could you elaborate on what you want?
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
21 Apr 2014 03:56 PM
You want the top surface of every block to line up with the next to of position correct?

you could do something like:

startPos = Vector3.new()
endPos = Vector3.new(0,5,5)
local part

local subCFrame = CFrame.new(startPos,endPos)-startPos
local offset = subCFrame*CFrame.new(0,-part.Size.Y/2,0)
local midpoint = (startPos+endPos)/2
local offset = offset+midpoint

part.CFrame = offset

I believe this should work correctly.



Alt. of Jetta765214
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
21 Apr 2014 04:03 PM
Thanks jetta that's a good way to line the parts up next to each other :D

But I still don't know how I would line them up when the part has a random rotation given to it, somehow you could probably use lookVector's but I can't figure out how.
Report Abuse
tommyfun is not online. tommyfun
Joined: 04 Jan 2011
Total Posts: 1404
21 Apr 2014 04:35 PM
I could give you a mathematical equation, but how you want it done is a little confusing.
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
21 Apr 2014 04:47 PM
I think i understand you better now, you want to rotate the block 135-160 degrees downward?

If this is what you meant, you can calculate the endPos using that data.

startPos = Vector3.new()
local part

local randomRotation = CFrame.Angles(0,0,math.random(135,160)/180*math.pi)
local endPos = startPos+randomRotation.lookVector*(part.Size.X/2)

local subCFrame = CFrame.new(startPos,endPos)-startPos
local offset = subCFrame*CFrame.new(0,-part.Size.Y/2,0)
local midpoint = (startPos+endPos)/2
local offset = offset+midpoint

part.CFrame = offset

Alt. of Jetta765214
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
23 Apr 2014 09:00 AM
The calculation you just did probably works, but I'm still a little confused.

I can't find how to use that calculation properly. I think it'd be clearer to me if somebody showed me a calculation from scratch, by doing Instance.new("Part"), and change the properties of that part to generate a slope like in this screenshot:

http://postimg.org/image/a8suk8cvt/

It'd just be a lot easier to understand the way you did it :>
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
23 Apr 2014 10:20 AM
function createPart()
local part = Instance.new('Part')
part.Parent = game.Workspace
part.TopSurface = 'Smooth'
part.BottomSurface = 'Smooth'
part.Anchored = true
part.FormFactor = 'Custom'
return part
end

local range = 5
startPos = Vector3.new()

for i = 1,50 do
local part = createPart()
part.Size = Vector3.new(1,5,range)

local randomRotation = CFrame.Angles(math.random(135,160)/180*math.pi,0,0)
local endPos = startPos+randomRotation.lookVector*(range)

local subCFrame = CFrame.new(startPos,endPos)-startPos
local offset = subCFrame*CFrame.new(0,-part.Size.Y/2,0)
local midpoint = (startPos+endPos)/2
local offset = offset+midpoint

part.CFrame = offset
startPos = endPos
end

Alt. of Jetta765214
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