Help with positioning gun

Blitz3D Forums/Blitz3D Programming/Help with positioning gun

Xzider(Posted 2007) [#1]
I have a gun im trying to position right in front of the camera on load, but it wont do it right.

This is very messy and I indent my code weirdly.

Function Load_Weapon(TempFile$,TempName$,TempAmmoMax%,TempAmmoCur%,TempAmmoType,TempWeaponDelay%,TempTexture$,TempColor1%,TempColor2%,TempColor3%,TempScale1#,TempScale2#,TempScale3#,TempRotate%)


        Weapon% = LoadMesh(TempFile$)

  If Not Weapon%

        RuntimeError "Error Loading Weapons!"

  End If

       WeaponName$ = TempName$

  If TempTexture$ <> ""

        TempWeaponTexture$ = LoadTexture(TempTexture$)

  If Not TempWeaponTexture$

        RuntimeError "Error Loading Weapons!"

  End If

  End If

  If TempTexture = ""

        EntityColor Weapon%,TempColor1%,TempColor2%,TempColor3%

  End If

        ScaleEntity Weapon%,TempScale1#,TempScale2#,TempScale3#

        WeaponID% = NewWeaponID()
        AmmoMax% = TempAmmoMax%
        AmmoCur% = TempAmmoCur%
        AmmoType% = TempAmmoType%
        WeaponDelay% = TempWeaponDelay%

        RotateEntity weapon,-180,180,0
        PositionEntity weapon,X#+0.8,Y#-0.5,Z#+1.4

        EntityParent Weapon%,Camera%

End Function




GfK(Posted 2007) [#2]
You're positioning it too close to the camera. Default camera 'near' range is 1 unit. Anything closer than that won't get drawn. I'd therefore assume that when you say "its not doing it right" you mean the gun is either partially or completely invisible.

If this doesn't help you'll need to provide more information:

1. What does X, Y and Z represent in your code?
2. What does "its not doing it right" actually mean?


Xzider(Posted 2007) [#3]
Sorry, XYZ are the Camera Coords, It is not positioning itself in front of the camera, I set its position at the camera(In front of it as well) and it only shows the gun when the camera is facing a certain direction. Say im turning one direction, load the gun in-game and it works, I free the gun and turn around (A different direction) and load the gun in-game, it positions itself at the camera and the same direction it faces last time, but not in front of the camera the second time


GfK(Posted 2007) [#4]
Oh right.

Why are you freeing and reloading the gun??

Anyhoo. Try this:

RotateEntity gun,EntityPitch(cam),entityYaw(cam),entityroll(cam)
moveentity gun,0.8,-0.5,1.4
entityparent gun,cam



Xzider(Posted 2007) [#5]
Ill try it now, I was going to free the gun when he switches guns and load the next one. Have any better ideas?


Xzider(Posted 2007) [#6]
It didnt work,it rotates fine but it seems to only want to position itself at the camera,a certain way, not in front of the camera. I have no clue...

Edit - Ok its almost like this, it will be in front of the camera. Free/Reload it doesnt stay with the front of the camera


jfk EO-11110(Posted 2007) [#7]
Suggestion: create a pivot at the gunhands position. Then you'll only have to position the guns at the pivots location and rotate it the way mentioned before.

Suggestion2:
Load all guns at level start, then hide them all and only show the active one. This will prevent any pauses for loading.