Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 24 Apr 2017 02:09 AM |
I'm attempting to "constrain" parts with BodyPosition. It's working better than actual constraints were for me.
I'm basically making a hover car. The Vehicle's PrimaryPart's BodyPosition (named vehicleHover) is set to 8 studs above ground level, plus math.sin(tick()) for a hovering effect.
The Fan's BodyPosition (fanHover) and the Turret's BodyPosition (turretHover) need to be the PrimaryPart's destination plus an offset. I did this by looping the following. I can loop very infrequently, because of the dampening effect of BodyMovers (yay!)
local hoverPos = Vector3.new(vehicle.PrimaryPart.Position.X+5,pos.Y+8+math.sin(tick()),vehicle.PrimaryPart.Position.Z+5)
vehicleHover.Position = hoverPos fanHover.Position = (CFrame.new(hoverPos,vehicle.PrimaryPart.Rotation)*CFrame.new(0,2.5,-6)).p turretHover.Position = (CFrame.new(hoverPos,vehicle.PrimaryPart.Rotation)*CFrame.new(-0.2, 4, 0.22)).p
-- This is the undedesired effect that is being produced... (qyazo) /f1b1c06991f29f8866d08a9d9940e4d2
My offset is somehow incorrect, and I'm not sure what I'm doing wrong.
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 24 Apr 2017 02:15 AM |
I assume these are the points of error:
CFrame.new(hoverPos,vehicle.PrimaryPart.Rotation) specifically the 2nd argument
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 24 Apr 2017 02:43 AM |
And I _especially_ don't understand this one...
/3c4bbad610003b48714f8eb85f583271
local hoverPos = Vector3.new(vehicle.PrimaryPart.Position.X+5,pos.Y+8+math.sin(tick()),vehicle.PrimaryPart.Position.Z+5)
vehicleHover.Position = hoverPos fanHover.Position = (vehicle.PrimaryPart.CFrame*CFrame.new(0,2.5,6)).p turretHover.Position = (vehicle.PrimaryPart.CFrame*CFrame.new(-0.2, 4, 0.22)).p
-- ^ how could this possible go wrong? I mean, it's not ideal because the turret and fan will lag behind the main vehicle body, but they should at least be properly offset..? Apparently not
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Apr 2017 03:41 AM |
The CFrame.new(Vector3 a, Vector3 b) constructor constructs a CFrame at point a and makes it "look at" b. When you set it to face the rotation you end up making it face near the origin of the map (some weird rectangle between (-18 0, -1 80, -1 80), (18 0, 1 80, 1 80)) Instead what you want to do is something like
fanHover.Position = hoverPos + primarypart.CFrame:vectorToWorldSpace(Vector3.new(0.2.5,-6)) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Apr 2017 03:42 AM |
(Referring to: "CFrame.new(hoverPos,vehicle.PrimaryPart.Rotation)")
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 24 Apr 2017 12:23 PM |
Thank you, that appears to be working, but out of curiosity, why didn't the 2nd work?
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 24 Apr 2017 12:24 PM |
That is, fanHover.Position = (vehicle.PrimaryPart.CFrame*CFrame.new(0,2.5,6)).p
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|