Jump to content

Weird problem with attached objects ( bone_attach )


McDeKi

Recommended Posts

Hey,

I've noticed that when the player is aiming the rotation of objects attached with bone_attach ( latest one ) is delayed.

aiming: the rotation/postion is delayed

normal rotation: everything works fine

  
local r = 0 
function s2() 
if r >= 360 then 
    r = 0  
end 
    r = r + 20 
    setPedCameraRotation( localPlayer,  -r ) 
end 
  
local w = false 
  
function s() 
w = not w 
if w then 
    addEventHandler('onClientRender', root, s2) 
else 
    removeEventHandler('onClientRender', root, s2) 
    end 
end 
addCommandHandler("ro", s) 
  
function s3() 
if r >= 360 then 
    r = 0 
end 
    r = r + 20 
    x,y = getElementRotation(localPlayer) 
    setElementRotation( localPlayer, x, y, r) 
end 
  
local wr = false 
function s4() 
    wr = not wr 
if wr then 
    addEventHandler('onClientRender', root, s3) 
else 
    removeEventHandler('onClientRender', root, s3) 
    end 
end 
addCommandHandler('po', s4) 
  

I've used this code for testing.

I've tried:

-setting player rotation to object rotation - didnt work

-attachElements ( the rotation and postion still were delayed )

-getting postion of muzzle ( getPedWeaponMuzzlePosition ) and passing it instead of getPedBonePosition - didnt work

-setCameraTarget ( the rotation still was delayed )

-setPedCameraRotation ( the rotation still was delayed )

-setCameraTarget + setCameraMatrix - didnt work very well, still was delayed

I think the problem is setElementRotation / setElementPosition

Its very big problem for me, cus I wanted to make a custom clothes for peds and the flashlight for weapons, but as you can see the rotation goes weird when the camera is being moved.

Any help will be greatly appreciated

Edit: Also I've tried SAMP's bone attach and everything worked fine :C

Link to comment

Try using onClientPreRender rather than onClientRender. By using onClientRender, you're taking the position of the bone just after it has been rendered, then setting the position of the attached object in the next frame, so you always see your attached object where the bone was the previous frame.

Your variable and function names are atrocious.

Link to comment
  • 5 years later...
  • Scripting Moderators
1 hour ago, Rilot said:

@McDeKi Hi! I was wondering if could you fix it. If you did, how? I have the same problem, I use bone attach for taser but when I aim, it's really delayed. Thank you!

This topic is from 2014. I doubt that he would answer you.

Did you tried to make attachment on client-side? If you create object at server-side then no wonder why it's delayed.

Link to comment
22 hours ago, majqq said:

This topic is from 2014. I doubt that he would answer you.

Did you tried to make attachment on client-side? If you create object at server-side then no wonder why it's delayed.

Ikr, it's old as hell. I didn't tried, if I'm correct, if I try it on client side, it's only gonna be showed for localPlayer. Or maybe I could do it with triggering server event or something, but that would give it delay too.

Link to comment
  • Scripting Moderators
13 minutes ago, Rilot said:

Ikr, it's old as hell. I didn't tried, if I'm correct, if I try it on client side, it's only gonna be showed for localPlayer. Or maybe I could do it with triggering server event or something, but that would give it delay too.

Attach with trigger, it will be shown for all players, but do not forget to create object directly on client-side. Delay before attached object will appear wouldn't be significant.

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...