graycontrast Posted July 19, 2016 Share Posted July 19, 2016 I am trying to create a platformer game where you can run, jump and shoot projectiles (lemons like in megaman). I am using 3-D models restricted to a 2-D plane. I already have my character running and jumping, however I am having a very difficult time trying to get shooting. I am not sure how to start. Should I have the chatterer controller script generate the projectiles? Can I make a global trigger that follows the character and emit the bullets? I am not sure where/how to generate the projectiles and where/how to do collision detection. can I have it shot a .pfb that I have made, or will it have to be a basic shape, or sprite? Thanks! Quote Link to comment Share on other sites More sharing options...
Genebris Posted July 19, 2016 Share Posted July 19, 2016 Prefab:Load and Script:Collision - this is all what you need. Quote Link to comment Share on other sites More sharing options...
Josh Posted July 20, 2016 Share Posted July 20, 2016 See the bullet script, it will work with any entity. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
graycontrast Posted July 21, 2016 Author Share Posted July 21, 2016 I was able to create a prefab when pressing the fire button using the "Prefab:Load" however my problem now is that it spawns at the prefab's default position and direction. How can I get the player's position and direction so I can add a self.entity:SetPosition(x,y,z) and self.entity:SetRotation(x,y,z) to the projectile script? Is there a way to pass that to the prefab as I load it? Or will I have to search the world entries? Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted July 21, 2016 Share Posted July 21, 2016 You can get the position of the player with local pos = self.entity:GetPosition(true) and the rotation with local rot = self.entity:GetRotation() Quote Link to comment Share on other sites More sharing options...
Genebris Posted July 21, 2016 Share Posted July 21, 2016 Prefab:Load returns created entity. Quote Link to comment Share on other sites More sharing options...
graycontrast Posted July 22, 2016 Author Share Posted July 22, 2016 here is my function. function Script:Fire() local bullet = Prefab:Load("Prefabs/Projectiles/testBullet.pfb") local pos = self.entity:GetPosition() local rot = self.entity:GetRotation() bullet:SetPosition(pos) bullet:SetRotation(rot) end and I am getting an error that says " attempt to index local 'self' (a nil value)" when trying to use self.entity:GetPosition() or self.entity:GetRotation() I am not sure why self is nil in this function. those commands work in the other functions Quote Link to comment Share on other sites More sharing options...
graycontrast Posted July 23, 2016 Author Share Posted July 23, 2016 I was able to get it to work. my call for the Fire function was wrong. it was self.Fire() not self:Fire() Quote Link to comment Share on other sites More sharing options...
Genebris Posted July 23, 2016 Share Posted July 23, 2016 self.Fire() is also correct, but it doesn't send "self" to a function which resulted in your errors. When you use "self:Fire" you make "self" accessible inside this function. Quote 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.