Slastraf Posted November 27, 2015 Share Posted November 27, 2015 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. Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 27, 2015 Share Posted November 27, 2015 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. 1 Quote 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 More sharing options...
Slastraf Posted November 28, 2015 Author Share Posted November 28, 2015 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. Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 28, 2015 Share Posted November 28, 2015 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. Quote 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 More sharing options...
Recommended Posts
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.