|
| 08 Sep 2014 02:37 PM |
Not sure how to explain what I'm attempting to do.
I need help figuring out an... equation? algorithm?
What I'm trying to do is make a tool that prints 2 Vector3 points in Workspace. The thing is, point A must be calculated at a random point and point B is meant to be found by the direction of the Torso & Point A, but farther away.
Think of a large circle around a smaller circle. Point A must be randomly picked inside the large circle but outside the smaller one and Point B is chosen by calculating the direction of Point A from the Torso. I don't know how math like that would be played out.
Does anyone think they can help me out here? |
|
|
| Report Abuse |
|
|
Bobobob12
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 08 Sep 2014 02:44 PM |
i think cross().unit is what you're looking for, since cross will find the angle between two vectors and then unit will normalize it, then you can multiply it by math.random(min,max) where min and max refer to the magnitude
assuming it must be farther than the second vector (farther is actually relative because left hand rule; it may end up the opposite direction and you'd need to define the axis it should follow given certain rotations of the torso or however you want to handle it) min would be the magnitude of pos-torsopos and max would be that + whatever you want the second radius to be
if you didn't understand that splurge of math that i kinda did a bad job with, feel free to question certain parts and i'll get back to you
also i was really vague defining cross because i don't know what u gotta do to work it ))):: |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 02:56 PM |
Woah bob slow down there Cross product is not for finding angles, the inverse cosine of their dot product is - but you don't even need that.
local function GetPoint(p1, p2, min, max) return (p2-p1).unit*(min+(max-min)*math.random()) end
print( GetPoint( PointA, Torso.Position, 10, 50 ) )
|
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 03:08 PM |
I didn't understand any of that. I looked it up on the wiki and I still didn't get it. I had to google it and I STILL didn't comprehend it.
If roblox would allow us to link images, I could show you, but since they can't I'll have to upload a decal to show you what I mean.
http://www.roblox.com/Reference-item?id=176975207 (You may have to wait for approval to see it, but there it is. 3 examples of randomly selected dots inside the chosen area, and their point B's farther down the line.
@nicemike I'll give that a shot, assuming I properly understand it. Just in case I don't, the link to the decal is above. |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 03:12 PM |
| Upload to lmgur, post ID here |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 03:16 PM |
Never mind apparently you can bypass the wait by subtracting one from the ID.
Anyways, that's what I thought so mine should work. |
|
|
| Report Abuse |
|
|
Bobobob12
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 08 Sep 2014 03:19 PM |
| oh god i did not think that was what she was asking at all |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 03:23 PM |
Actually Mike, after Defining Torso (Which I went ahead and changed to BasePlate for simplicity)
I got this error.
15:21:22.760 - Workspace.Script:2: bad argument #2 to '?' (Vector3 expected, got nil) 15:21:22.761 - Script 'Workspace.Script', Line 2 - local GetPoint 15:21:22.762 - Script 'Workspace.Script', Line 5 15:21:22.762 - Stack End
I don't know much about math, but my common sense tells me that it's referring to PointA |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 03:26 PM |
My common sense tells me that you never defined PointA Or you didn't give the function 4 arguments |
|
|
| Report Abuse |
|
|
Bobobob12
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 08 Sep 2014 03:50 PM |
once you fix whatever your issue is, note that GetPoint returns everything in reference to the world, so you should use mike's fix like so
local PointA = Vector3.new(0,0,0)
Torso.Position + GetPoint(Torso.Position, PointA, 10, 15)
Also Torso.Position would be the first argument since you're using it as the reference frame, as mike may have misinterpreted.
A cheekier CFrame solution (since they always are in reference to the object) would be
CFrame.new(Torso.Position, PointA) * CFrame.new(0,0,math.random(10, 15)) |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 03:54 PM |
| I'm not supposed to define PointA. Torso is the origin, PointA is supposed to be the vector randomly defined by getting a random vector in a 360 degree radius between minimum distance and maximum distance. PointB is in the same direction from the point of origin, just farther along that directional line. |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 03:59 PM |
| Ill fix it in like4 hours I got things to do |
|
|
| Report Abuse |
|
|
Bobobob12
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 08 Sep 2014 04:08 PM |
well yes, i think he assumed you could do that on your own.
you can use GetPoint to make a (roughly) random PointA
local PointA = Torso.Position + GetPoint(Torso.Position, Vector3.new(math.random(-100,100), Torso.Position.y, math.random(-100,100), 2, 10)
local PointB = Torso.Position + GetPoint(Torso.Position, PointA, 10, 15)
tada
this assumes you're only looking for no effect to be had on the y axis, otherwise replace a.Position.y with math.random(-100,100) |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 04:10 PM |
| Take all the time you need. |
|
|
| Report Abuse |
|
|
Bobobob12
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 08 Sep 2014 04:10 PM |
| also missing a parenthesis there after the final math.random(-100,100), watch that |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 05:07 PM |
I have never come across anything so hard to understand before.
By the way, where's the radius? |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 07:55 PM |
OK I finally understand what you want to do. How much further along the line is point B supposed to be? |
|
|
| Report Abuse |
|
|
Bobobob12
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 08 Sep 2014 08:36 PM |
the radius is a random number between 2, 10 in the code i posted
then the minimum radius of pointb is 10 since its a's max
you can change any of these values |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 08:58 PM |
Sorry I was watching ghostbusters.. xD
I'll try to explain the decal. The black dot in the center represents the point of origin, any part in workspace. I was using Torso to make it simple. The red, green, and blue lines are just examples of what I'm trying to accomplish. The small circle represents the minimum distance I guess of... magnitude? unit? from the point of origin, while the large circle is the maximum distance. Let's use the red line as the example. The red line represents "direction". The red dot (between the minimum distance and maximum distance) closest to the black dot is Point A, randomly chosen in the area AROUND the player, the radius of the player. (is radius the right word for this? Perhaps circumference? Either way Point A must be randomly chosen anywhere in that big white circle between the small black circle and big black circle. Point B is chosen on the same "line" or direction, just farther outwards, the red dot at the end of the line.
For your needs in order to properly help, let's make a defined distance just to make sure everything is working.
Minimum = 10; Maximum = 20 PointB's range farther out can just be 5 units.
Does this help explain things properly?
I'm sorry if I'm difficult to help. I get these weird project ideas and I just have to do them. |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 09:34 PM |
I got all that, all I needed to know was 5 studs further lol but alright
codepad/0X9jzWbv
That was a fun thing to do instead of homework lol |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 09:44 PM |
I see you did all 3 colors... o.o
It's cool I'm sure I can study this and get a pretty good grasp of this. I'll let you know how this pans out. :) |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 09:48 PM |
Everything after the documentation is just fluff that you don't need, btw.
And it's really just some basic trig and reallly simple vector math |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 09:49 PM |
Wow yes, this is absolutely amazing! I'm learning things here that I never dreamed about being able to understand but this is easier than I thought it would be. o.o
Although... I'd have to be smarter in math to understand how a cosine works and that, but as long as I know what it does I'm sure things will work out.
Thank you very much for being patient. I know I'm not the easiest person to work with. This is going to come in extremely handy when I make the helicopter for the care package. (Yep... I said care package XD) |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2014 09:59 PM |
Actually, it seems it's not entirely right.
I did try a basic test to see what I'm dealing with and changing the:
minRadius = minRadius or 3 maxRadius = maxRadius or 8 furtherOut = furtherOut or 100
didn't seem to have any effect at all. |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 08 Sep 2014 10:03 PM |
If I understood the OP correctly, all of you are way overthinking this.
direction = (PointA - Torso.Position).unit PointB = Torso.Position + direction * newDistance |
|
|
| Report Abuse |
|
|