Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Vector3.y only, without x and z?

Asked by 10 years ago

engine.RotVelocity.Vector3.y = (vehicleSeat.Steer*steeringSpeed)

I know, the line above is totally broken. How do I move Vector3.y only without moving x and z?

0
It is the same as what you did, I believe, but instead of using "RotVelocity.Vector3.y" use "RotVelocity.y" SlickPwner 534 — 10y

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

A Vector3 doesn't have a Vector3 property, so obviously your line is wrong.

It does have a y property, though, so it might look like this:

engine.RotVelocity.y = vehicleSeat.Steer * steeringSpeed;

However, we can see here that all of a Vector3's properties are read only.

We have to set the Vector3 value as a whole.


If you want the X and Z values to be zero, it's easy to just construct a new one:

engine.RotVelocity = Vector3.new( 0, vehicleSeat.Steer * steeringSpeed , 0);

If you want this to not affect the X, and Y values, we can either do a little amount of Vector math, or just read the coordinates ourselfs:

local previous = engine.RotVelocity.y;

local withoutY = previous * Vector3.new(1, 0, 1);
-- Does component-wise multiplication
local Y = Vector3.new( 0, vehicleSeat.Steer * steeringSpeed , 0);
engine.RotVelocity = withoutY + Y;

or

local previous = engine.RotVelocity;
engine.RotVelocity = Vecto3.new( previous.x, vehicleSeat.Steer * steeringSpeed, previous.z );
Ad

Answer this question