Assume that i have the angle of impact on this part (could really be any part). This is then a vector3
How can i add “force” to this angle. I want to create a vector3 which is basically applying force to this point, on a specified angle.
Here is what i have tried:
local function Force(ray, raycastAngle)
local part = ray.Instance
local force = 500
local RelativeVector = part.CFrame.LookVector -- In this case the arm
local ImpactAngle = -(RelativeVector - raycastAngle)
-- Since applyimpulse is based on a relative angle, impact angle is the angle
-- we want
ray.Instance:ApplyImpulse(ImpactAngle * force) -- flings the part with the force of 500, based on
-- the impactangle. This snippet is the one thats wrong
end
You need to keep track of the direction of the ray, which is the Vector of the ray, but normalized. For example:
local rayOrigin = ...
local rayVector = (rayTarget - rayOrigin)
local rayResult = workspace:Raycast(rayOrigin, rayVector)
-- `.Unit` returns the "Normalized" Vector3, which points in the same direction,
-- but is only 1 unit long
local rayDirection = rayVector.Unit
The first value is an impact angle, the second is a equivalent raycast unit direction.
-56.15999984741211, -51, 0
-0.43277668952941895, 0.8305954933166504, 0.3504503667354584
But i do wonder, assume that i only have the angle. How do you calculate it then.
You can’t. There’s no axis, an angle is just a number. You need a direction to apply a force, that’s what a force is, you can’t apply one with just an angle out of context.
You can’t just have an angle. Angles are only meaningful in 2 dimensions, but we work in 3. You need 2 axes to have it make sense. The angle between these 2 lines is 45*,
This doesn’t provide any useful information, because if I rotate the diagonal line around the horizontal line, the angle between them doesn’t change even though I have an entirely different direction.
This isn’t an angle. An angle describes the difference in direction between 2 direction, if both start at the same point. It’s a single number. What you have there is (I assume) a vector, which is a direction. You can’t have a 3 dimensional angle, just like you can’t have 3 dimensional time (it’s just 1 number)
RelativeVector - raycastAngle is not an angle, nor is it a direction. It is meaningless, because RelativeVector is a “Forward Vector” that represents the direction the Part is facing (if you do Part.Position += Part.CFrame.LookVector it will move forward 1 unit), it’s components are from 0 to 1, and Part.Orientation represents actual rotations from -180 to 180. They do not represent the same type of data, and substracting one from the other doesn’t give anything useful.
Can’t they just use the raycasts Normal multiplied by *-1 and then multiplied by a value to determine the intensity? If you make the normal result *-1 it would essentially just be the direction no? The normal is just a unit vector that is the rays “reflection” of the surface. If you multiply it be negative 1 you’ll get the direction as a unit vector. Then multiply it by a number and you have your knockback force.
Yeah. That is what i was sort of thinking. I forgot that after you use orientation, you have to add force to where its looking. knowing this, I could create an instance, change the orientation of the instance to the orientation and then shoot it using lookvector*force. Any ideas on how to not create an instance to save on RAM?
No, it would be 180 degrees within the ray direction. It will only be equal if the surface is perpendicular to the ray, making the normal and ray direction parallel.