|
| 23 Jul 2012 04:43 AM |
| Hello, right now I am trying to create a hovercraft. I already made the hovercraft and it glides a set number of studs above the ground and can move forward using a vehicle seat, but I need a way to turn it. I have tried practically everything from RocketPropulsion to BodyAngularVelocity. The script where I set it to turn is in a function and I have the changed event controlling when to turn, I just need a way to make it turn. Kthx. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 04:52 AM |
Here is the code for checking the direction, if you need it, this part works fine though.
script.Parent.Changed:connect(function(property) print("changed") if property=="Throttle" then print("throt") local prop=script.Parent.Throttle if prop==1 then moving=false wait(0.1) moving=true goDirection() elseif prop==0 then moving=false goDirection() end elseif property=="Steer" then print("steer") local prop=script.Parent.Steer if prop==1 then turning=false wait(0.1) turning=true turnDirection() elseif prop==-1 then turning=false wait(0.1) turning=true turnDirection() elseif prop==0 then turning=false turnDirection() end end end) |
|
|
| Report Abuse |
|
|
Cheater
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 5258 |
|
| |
|
DoctorEvo
|
  |
| Joined: 22 Apr 2008 |
| Total Posts: 199 |
|
|
| 23 Jul 2012 05:35 AM |
BodyAngularVelocity worked spectacularly for my helicopter.
Show me what you're using for the propulsion half of this. If it's anything like a typical plane's FlyScript, you're gonna be in neverending conflict with a while loop killing your angular velocity ten times a second. Notice:
------------------------------------ local engine = script.Parent.Parent.Engine local spd = 3 local position = engine.Position
while true do wait(.1) direction = engine.CFrame.lookVector position = position + spd*3*direction error = position - engine.Position engine.Velocity = spd*error engine.RotVelocity = Vector3.new(0, 0, 0) --THIS line right here. THIS will git ya. end |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 05:53 AM |
| Well, BodyAngVel worked for moving, but it didn't quite turn the vehicle. It only made it start moving left. I should probably say this, the way the hovercraft works is with a couple of pads in the bottom using BodyPosition to keep the hovercraft above the ground at 8 studs. This means that if the hovercraft is pushed, it will keep moving and moving without stopping, which I assume is what happens with the turning. For the movement part, the only thing I could get to work smoothly was the old bunny, carrot, and fishing rod trick. I welded a brick just in front of the hovercraft and made the engine of the hovercraft move towards it. If I knew how, I would use BodyThrust or BodyVelocity. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 06:13 AM |
Heres the code:
local function goDirection(go) local bp if not hm:findFirstChild("RocketPropulsion") then print("nobp") bp=Instance.new("RocketPropulsion", hm) bp.ThrustP=speed bp.TurnP=turnspeed bp.MaxThrust=100000 bp.MaxSpeed=speed bp.Target=script.Parent.Parent.front else bp=hm.RocketPropulsion end if go then bp:Fire() else bp:Abort() hm.Velocity=hm.Velocity*Vector3.new(1, 1, 0) end end |
|
|
| Report Abuse |
|
|
DoctorEvo
|
  |
| Joined: 22 Apr 2008 |
| Total Posts: 199 |
|
|
| 23 Jul 2012 06:59 AM |
Eh, yeah, that is sorta hack. I'd recommend using BodyThrust for this particular application, and BodyAngularVelocity for steering. The great thing about BodyThrust is that it is actually in object coordinates, so you don't even have to worry about finding the forward vector at all.
I do recommend adding a BodyVelocity with Velocity = 0,0,0, MaxForce = inf,inf,inf, and low P (adjust yourself to find the right strength) to simulate drag and keep your speed under control, though. Those three together (four, if you count your BodyPosition) will probably get you very nice handling with next to no difficult scripting.
-Doc |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 08:16 AM |
| I got it working. Rather than going through a bunch of trouble, I ended up simply using BodyVelocity to move, multiplying my speed var by the engine's lookVector and keeping a turn setting of around 3 using BodyAngVel. Then in the script that makes it hover, if there are no blocks underneath the hovercraft, it will continue to delete every new BodyVelocity to prevent flying in mid air. I made a small hovercraft with this, and it glided over terrain like a bar of soap on ice. The best part it, it is adaptable to any size aircraft as long as it has scanners on the bottom. Thx for the help. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 08:17 AM |
| P.S. No need to simulate drag, hovercrafts don't tend to have that. |
|
|
| Report Abuse |
|
|
DoctorEvo
|
  |
| Joined: 22 Apr 2008 |
| Total Posts: 199 |
|
|
| 23 Jul 2012 11:02 AM |
Trust me, they DO have it, and it is ESPECIALLY important on a model like the one I described, because otherwise you would end up with unlimited top speed, as the force from a BodyThrust does not diminish with speed (unless you script it to, like I did with my helicopter). Now, it is true that they do NOT have significant friction with the ground, which is the reason behind their unusual handling properties, but if you end up creating lateral forces similar to friction anyways, it will create improper handling regardless of whether or not your hovercraft actually touches the ground.
Now, the method you used is functionally identical to using BodyThrust (albeit in a more roundabout way), since the vector math you used combined with the BodyVelocity's internal mechanics will result in a near-constant thrust pointed in the forward direction, so it should work similarly regardless. I'd like to know how it handles when you're done with it, and if it indeed does end up having any sort of a top speed. |
|
|
| Report Abuse |
|
|
|
| 23 Jul 2012 12:37 PM |
| It works great. It zooms right over the terrain and surprisingly over water, but it isn't really good with jumps. The whole goal of this was to make a vehicle that could go any set speed without friction slowing it down, and without 'flying'. I might make a more realistic version, though. For example, instead of stopping when you let go of forward it slides a bit and more difficult steering. But for now, with the method I am using it can go any speed I want it to and turn at any rate. To be honest, there is no top speed, this hot rod can bolt as fast as it wants across rugged terrain. |
|
|
| Report Abuse |
|
|
DoctorEvo
|
  |
| Joined: 22 Apr 2008 |
| Total Posts: 199 |
|
|
| 23 Jul 2012 01:50 PM |
Sounds awesome. Makes me want to try building one...
Would you mind if I did? I'd show you how I did it after I finished, and then maybe you could take the best parts of each and combine 'em. |
|
|
| Report Abuse |
|
|