Jump to content
graycontrast

Need help creating projectiles for a platformer

Recommended Posts

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!

Share this post


Link to post

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?

Share this post


Link to post

You can get the position of the player with

 

local pos = self.entity:GetPosition(true)

 

and the rotation with

 

local rot = self.entity:GetRotation()

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...