Why isn't this code working?

I’m currently trying to rotate a vector onto the camera plane.

((camera.CFrame.Rotation * CFrame.new(hum.MoveDirection)).Position

This code is supposed to add the movedirection vector of the humanoid to the rotation of the camera, but it doesn’t. The reason why I need this, is because I’m trying to “unlock” the character movement. Usually you can only move on a plane that looks like this: 0, 1, 0. Flat. But I want the plane of movement to be parallel to the orientation of the camera. If you were looking directly down, pressing w would allow you to move directly down, A, left, and S up. Don’t worry about how I’m getting the character to move directly up, I just need this vector.

How do you rotate a vector?

3 Likes

I think the problem could be because you are using the movement of the player and not the LookVector of the HumanoidRootPart, but that could just be me, from what I know this way you will only get your effect if your are moving

1 Like

So you’re saying I should do

((camera.CFrame.Rotation * CFrame.new(hum.MoveDirection)).LookVector
1 Like

No instead of hum.MoveDirection maybe use hum.LookVector? I’m not a programmer so I’m not sur if it will work

1 Like

hum.LookVector doesn’t exist. That’s not a valid property of Humanoid

And also, I’m not sure but wouldn’t your code affect the camera and not the player? As I said I’m not a programmer so…

Oh then try doing that for the HumanoidRootPart?

1 Like

I see, but unfortunately that won’t solve my problem, because the humanoidrootpart always looks forward.

Oh, then I don’t know sorry :person_shrugging:

1 Like

camera.CFrame.LookVector will point in the direction of the camera

function rotateVectorAround( v, amount, axis )
	return CFrame.fromAxisAngle(axis, amount):VectorToWorldSpace(v)
end

Simple as that! x

I’ve seen this code before on devforum, I think it was by @ThanksRoBama . But I don’t understand it.

1 Like

Ok, I’m not a programmer but I think I might be able to explain it, first, the

function rotateVectorAround( v, amount, axis )

This should create a function that gets when the vector is rotated, I don’t know what v is, but amount should be the offset (ex. 130) and the axis is the axis, now

return CFrame.fromAxisAngle(axis, amount):VectorToWorldSpace(v)

This returns the CFrame with the axis and the offset (ex. 130 on the X axis) but I don’t know what VectorToWorldSpace means, sorry, and now

end

This is probably the hardest part to understand of the script, it ends the script.

Sorry, I’m not a programmer, I don’t garantee that this is what the script means, but from my little understanding of scripts this is what I interpreted from it, have a good day/night

1 Like

can’t you just like renderstepped the camera cframe to -4 z behind the player’s head in objectspace

I don’t think everyone understands what I’m trying to do. Right now with normal character physics, you can only move forward, backwards, left, and right. I want the character to be able to move in those same directions, but relative to the camera. How? What math would I need?

Ok, you first have to get the axis and offset of the camera, @0hJudas’s script does that, and after that you will have to modify the behaviour of the commands of the movement of the player, from what I understand you are trying to make the effect of being underwater in first person but In third person and out of the water? Right?

No, this is because in my game you are in space, so I need the character to move in relation to where you are looking, not based on the world axis.

Could you explain the practicality of this? I don’t understand CFrame.fromAxisAngle(). I’ve never used it.

Ok, then you could try and fill the world with a block and make a script that makes the player have the swimming state activated, but there’s still the problem of the camera thing, but this would make the problem of going up/down solved

That’s a really good idea, but I want there to be some kind of ball physics. Swimming is just linear. I want them to be able to speed up, slow down etc.