Hi! I am scripting a helicopter with CFrame and I got the main framework almost done. Helicopter can turn left and right and can fly in all directions. robloxapp-20210408-0823046.wmv (2.3 MB) , now my next task is to rotate the helicopter a little bit forward when flying forward. As u can see I want to achieve “velocity excluding the rotation” but also be able to add CFrame acording to turnAngle - left and right so I can steer.
Here is what happens if I just try to add forward angle. robloxapp-20210408-0840020.wmv (2.1 MB)
Here is my current code (with using forwardAngle) :
I always like to think of the :Inverse() method as negating a CFrame, this way you can have ““CFrame subtraction””, subtracting cf1 from cf2 is like doing cf1:Inverse() * cf2. If you have a CFrame cf that has both a position and a rotation, and you want to subtract that rotation from it, technically you need to get the rotation CFrame part (which is really just cf - cf.Position) and subtract it, you have cf * (cf - cf.Position):Inverse() and I believe this operation is commutative.
Can’t tell exactly what you’re trying to do. Do you want it to do the same thing as in the video, but without up or down movement? Try explaining how you want the movement to be
Do you want the velocity to be like the blue vector or the dotted orange vector?
robloxapp-20210408-1416373.wmv (2.2 MB)
I want to tilt the helicopter while moving, but the forward or backward move is in relation with world space rather then object one. The correct movement is presented with Vx
First of all I’d change the names of your frontVelocity and similar variables. They seem to refer to a speed, NOT a a velocity. A speed is just a number, or a scalar in fancy terms. A velocity is always a vector, since we’re working in 3D a Vector3. The way you’re using those variables leads me to believe that they’re numbers, not Vector3s, so they can’t refer to velocities. From here I’ll assume those variables are renamed to frontSpeed, etc.
I would also break your loooong statements onto multiple lines for readability.
Using the changed code as a starting point, I’d try something like this:
-- The velocity of the chopper in relation to the chopper
local v_objectspace = Vector3.new(
frontVelocity * step - backVelocity * step,
upperVelocity * step - lowerVelocity * step,
0)
-- Velocity in relation to the world
local v_worldspace = helicopter.CFrame:VectorToWorldSpace(v_objectspace)
-- Velocity in relation to the world, with the up/down component set to 0
local v_horizontal = v_worldspace * Vector3.new(1, 0, 1)
--Translate the chopper by the world-space horizontal velocity
helicopter.CFrame += v_horizontal
helicopter.CFrame = CFrame.new(helicopter.Position) * CFrame.Angles(
0,
math.rad(turnAngle),
-math.rad(forwardAngle)
)
okay you achieved what I want, but now I cant use Q or E (steer heigth)
It was actually simplier than I thought…
I just added CFrame.Angles(0,0,math.rad(forwardAngle))
like that: