I have a velocity vector and a mouseposition vector I want to rotate the velocity vector towards the mouseposition vector a set amount of degrees (3D)
(green=velocity,red=mouseposition)
what I esstinally want
The usecase for this is that I have a projectile that shoots forward and then the player is able to control the projectile with there mouse, which I am using the mouseposition for
I know how to get an angle between 2 vectors using dot product however I am a bit lost on what to do with that information since I need to rotate 2 axis and dot product only gives me a scalar number
Because then it be instantaneous I need it to rotate towards the direction with a set amount of degrees, so if the angle between the 2 vectors is 180 it doesn’t just snap
I don’t understand your question I don’t think I ever said I needed to lerp, I just have a projectile that shoots forward and Im representing that movement by “velocity”
I don’t think you understand what you need. Use TweenService to tween (smoothly interpolate) the projectile to be in the direction of the mouse. That is what that service is for.
Edit: Otherwise you need to use a rotation matrix - you can’t rotate a 3D vector to another 3D vector by itself without a matrix. This is accomplished with CFrame.new(pos, targetPos)
Although using runservice is very fast its not a reliable method since there no gunatureed method it will clamp between desiredangle,maxangle… as for the fraction there be wasted movement since if you can imaigne 2 vectors being very close to each together (small angle) then it will have a hard time reaching to that point since it would then be a small number
Yes, but don’t ignore TweenService. You need to use it so it doesn’t “snap” to the new position. There’s a reason I keep telling you about it - I’m not just randomly throwing it out there.
Use a tween with CFrame.new(pos, targetPos) to tween the projectile to face the new mouse direction (rotate the vector).
local projectile = ? -- Your rocket or whatever
local ts = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1) -- 1 is the time of interpolation for the tween
local tween = ts:Create(projectile, tweenInfo, {
CFrame = CFrame.new(projectile.Position, mouse.Hit.p)
})
tween:Play() -- Run the tween
Dot Product is telling you how close one vector is to pointing towards the other. If the Dot Product is 1 then both vectors are in the same direction. -1 means they are both facing opposite sides. 0 or -0 means they are perpendicular to each other.
A little confused by the question can you further elaborate on what you mean by controlling the projectile with the player mouse. Specifically how that relates to needing to rotate a vector?
As an addition to @EgoMoose’s question, could you also explain your diagrams as its difficult to see what your end goal is when you then proceed to talk about the mouse controlling the projectile (the diagrams don’t relate)?
I’m assuming you want a projectile which you can fire, and then your mouse can influence how it moves through the air?