Jump to content

Recoil system


mafioz

Recommended Posts

 

4 minutes ago, shishani said:

No. For any weapon

try this code (client)

local coef = 0.5

addEventHandler ("onClientWeaponFire", root, function()
	if source ~= localPlayer then return end
	local x, y, z, lx, ly, lz = getCameraMatrix ()
	setCameraTarget (lx, ly, lz + coef)
end)
Edited by AngelAlpha
Link to comment

 

6 minutes ago, AngelAlpha said:

 

try this function 

local coef = 0.5

addEventHandler ("onClientWeaponFire", root, function()
	if source ~= localPlayer then return end
	local x, y, z, lx, ly, lz = getCameraMatrix ()
	setCameraTarget (lx, ly, lz + coef)
end)

Does not work. The player's camera rotates approximately 180 degrees.

Link to comment
13 hours ago, Spakye said:

Здравствуйте, попробуйте заменить setCameraTarget(...) на setCameraMatrix(x, y, z, lx, ly, lz + coef)

Если это не сработает, вы также можете попробовать что-нибудь с помощью get и setCursorPosition.

Hello. Thanks for your reply.

When using setCameraMatrix I won't be able to rotate the camera.

The only function to do this is setCameraTarget, now we need to get the correct camera direction to move it up a bit.

Edited by shishani
Link to comment
4 часа назад, Скай сказал:

setCameraTarget не позволяет вам, к сожалению, переместить его вверх.

Вы видели эту тему?

 

I want vertical recoil, not horizontal.

 

 

Link to comment
local coef = 0.01
function test(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement, startX, startY, startZ)
	if source ~= localPlayer then return end
	setCameraTarget(hitX, hitY, hitZ + coef)
	local rot = 360- getPedCameraRotation(localPlayer)
	setPedCameraRotation ( localPlayer, rot + 0.5 )
end
addEventHandler("onClientPlayerWeaponFire", root, test)

 Try this, its not neat, there is some math to do but its a start

Edited by Spakye
  • Thanks 1
Link to comment
2 hours ago, Spakye said:
local coef = 0.01
function test(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement, startX, startY, startZ)
	if source ~= localPlayer then return end
	setCameraTarget(hitX, hitY, hitZ + coef)
	local rot = 360- getPedCameraRotation(localPlayer)
	setPedCameraRotation ( localPlayer, rot + 0.5 )
end
addEventHandler("onClientPlayerWeaponFire", root, test)

 Try this, its not neat, there is some math to do but its a start

setPedCameraRotation rotate camera relative to the Z axis

Link to comment

Mate just start the game and try this it does what you want. It does need more work to make it look nice though 

the cam rotation is just here to fix the camera going a little bit to the right because im lazy to do some math to find precise positions.

Edited by Spakye
Link to comment
7 hours ago, Spakye said:

Приятель, просто запусти игру и попробуй, она делает то, что ты хочешь. Но нужно больше работать, чтобы это выглядело красиво 

вращение кулачка просто здесь, чтобы зафиксировать движение камеры немного вправо, потому что мне лень заниматься математикой, чтобы найти точные положения.

This function rotates the camera to the right or left, so the function is not suitable.
I need the camera to be pointing up for vertical recoil.

Link to comment
On 7/1/2022 at 6:33 PM, Spakye said:

As i said, it does what you want.

Yes, I didn't notice the setCameraTarget function in your code, it really works.

But I would like the sight to rise up smoothly, and not abruptly.

Thank you 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...