You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make my viewmodel move back a little bit using raycasts to prevent my viewmodel clipping into walls
What is the issue? Include screenshots / videos if possible!
I don’t know how to achieve such an effect I’m using Bind To render step for most of my major actions so im assuming if I was to use raycast I would need it to update constantly.
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I went looking for solutions on the forum but I can’t find one that explains how to achieve it well
Edit: There are a few notes there, thats for my team
Here’s a potential solution:
Raycast forward x amount of studs (change per gun), and then if the ray hits an object, either play an animation or apply a rotation offset to the viewmodel’s CFrame.
local viewmodelCFrame = ...
--// use rayParams, only collide with the map
local ray = workspace:RayCast(camera.CFrame.Position, camera.CFrame.LookVector * gunLength)
if ray then
--// Apply offset, either through animation or changing Yaw, Pitch and Roll.
viewmodelCFrame *= ... --// Better if you lerp a value, but this is a straight forward fix
end
viewmodel.CFrame = viewmodelCFrame
Additionally to that, if you’d want the animation to be a little more “real”, you could make the amount of rotational offset thats applied to the viewmodel base itself off how long the ray is, near max distance = barely any rotation, near min distance = almost all rotation.