Jump to content

Cant get bullet to be child of turret


Slastraf
 Share

Recommended Posts

post-12189-0-50448600-1448648881.png

The picture shows how I set up my turret.

http://pastebin.com/vDrh15pd

This is the script I attached to the turret.

When I am ingame the bullet is still rotated 0,0,0 and only after some time it follows the turret.

The turret is looking at the target, which is the enemy.

When the turret calls the Shoot() function the bullet flies somewhere but the -z axis on the local (space?).

It seems like the muttle pivot is no real child of the turret.

Link to comment
Share on other sites

You would make this a lot easier for anyone willing to help you if you posted the model with its entity script. Just providing the script doesn't allow anyone to easily test the code especially when the model's submeshes inherent orientation may be screwing up the math if they are not aligned to the global axis. But just a quick look at the script, I see a couple of issues.

 

First, you are missing out on the whole reason to use instancing since you are creating a new bullet each time the Script:Shoot() function is called. Create and Hide the bullet in the Script:Start() function and then instance that in the Script:Shoot() function.

 

Second, I replied in your previous post yesterday about this same topic on how to do physics bullets. You are not doing either of the two ways I showed how it could be accomplished. Either calculate the forces on the global axis required to make the bullet shoot in the right direction or set the bullet's position/rotation in relation to the turret's/muzzle's local axis position/rotation and apply a force to the bullet on its Z-axis.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

First, you are missing out on the whole reason to use instancing since you are creating a new bullet each time the Script:Shoot() function is called. Create and Hide the bullet in the Script:Start() function and then instance that in the Script:Shoot() function.

I fixed that for now, i see what i did wrong.

My shoot() function looks like this now:



function Script:Shoot()
local bullet = Model:Box()
bullet:SetScale(0.1,0.1,0.1)
bullet:SetColor(Vec4(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255,1))
bullet:SetPickMode(0)
bullet:SetPosition(0,-10,0)
      bullets = bullet:Instance()
           bullets:SetPosition(self.muzzle:GetPosition(true))
bullets:SetRotation(self.muzzle:GetRotation(true))
           bullets:Show()
           bullets:SetMass(1)
           bullets:AddForce(0,0,-2000,false)
end

It works fine now, maybe i set the script up too fast.

Link to comment
Share on other sites

I fixed that for now, i see what i did wrong.

My shoot() function looks like this now:



function Script:Shoot()
local bullet = Model:Box()
bullet:SetScale(0.1,0.1,0.1)
bullet:SetColor(Vec4(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255,1))
bullet:SetPickMode(0)
bullet:SetPosition(0,-10,0)
bullets = bullet:Instance()
bullets:SetPosition(self.muzzle:GetPosition(true))
bullets:SetRotation(self.muzzle:GetRotation(true))
bullets:Show()
bullets:SetMass(1)
bullets:AddForce(0,0,-2000,false)
end

It works fine now, maybe i set the script up too fast.

 

er... you still are creating the bullet in that function? Place that bit of code in the Script:Start() function as 'self.bullet = Model:Box()', scale it, set the pickmode, and hide it. Then instance the self.bullet in the Script:Shoot() function.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...