Math question - how can i rotate a vector so that it is in relation to characters orientation?

I use a timeline to add relation location and rotation the camera for camera shakes here:

I would like for some camera shakes to by related to the characters orientation. For instance, when the character slides, the camera should move in same direction as characters forward vector.

Right now the camera shake is defined by a curve. For this shake I have a curve that adds 100 units of location to the cameras X location over a second.

I think the simplest thing to do is to get the player character mesh orientation and use this to rotate the vector that will update the cameras relative location.

The code I have above doesn’t seem to get the characters orientation. As you can see in the gif, the rotation seems to be fixed to world space:
GIF 8-21-2023 5-24-54 PM
The second camera shake is correct - it moves towards the characters movement direction, but that is just incidental because the vectors are aligned. But I need for the vector to always be rotated in relation to the characters capsule or mesh rotation. FOr instance, if the character is running towards the camera and slides, then the camera should be moving backwards.

I’m not good with math at all, I think I have the right idea about what to do, but not sure how to say it in math terms. Anybody got some tips?

Here’s a graphic if it helps:

If you need just a shake, you can use CameraShake.

image

It has to be relative to the characters orientation though, so a simple shake won’t do. The camera is meant to move in same direction as the character mesh in this instance.

It doesn’t need rotation or location, CameraShake does it automatically.

if you want to help, reread the question in full.

Oh, I didn’t get first time, sorry.

So, you need to move camera in a dirction that character is looking? No mater to camera rotation?

yeah so I have a curve that says “over 1 second, move camera in X axis 100 units”.

By default this means camera just always moves along its on X (forward) axis.

But if the character is running towards the camera and slides, then the camera should move in the opposite direction. Or rather, the camera should always move in the direction that the character is sliding.

So we have a curve that tells us what the cameras relative location change should be. That I prefer to stay constant because I have a whole system built around it.

So with that as constant, then I just need to figure out how to say, “given the difference in rotation between the character mesh and the camera, use that difference to align the location delta before applying it as relative location to the camera”

You probably need something like that.

This confirms the basic theory:

However it’s not working in my full example. Should be able to figure it out though.

The important thing is that we are adding relative location to the camera, we can’t just set it in front of players location. I think the simplest way to say it is that I need to rotate one vector to align with another.

Should do the trick


@Shunitzo , you are the hero for the day.

One small amendment was necessary:

Need to use the cameras transform in the inverse transform node, otherwise always moves in cameras X regardless of player orientation.

Also for some reason need to use right vector, perhaps because the mesh is rotated 90 degrees.

Devlog

Actually was getting some problems with that setup. The orientation is always correct, however its like 50/50 if the movement happens or not. Cannot figure out why. Its not an execution flow thing, all the nodes firing correctly. Just that sometimes you get the full movement, other times doesn’t seem to move at all.

Well, I figured out an alternate way that seems to work 100% and is a bit simpler:


Since the spring arm is “stuck” to the player mesh anyway, we can actually just move it in world space relative to the player. This is simple enough that I can understand it and accomplishes same task.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.