how do i make npc shoot stuff?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

how do i make npc shoot stuff?

Postby lolcode » Thu Aug 05, 2021 7:09 am

I kinda know how to make npcs but i don't know how to make them spawn projectiles. I need the projectiles to have certain speed. Please help!

Lucario
Blooper
Blooper
Posts: 172
Joined: Thu Dec 10, 2020 11:54 am
Flair: A beginner Mario-level modder that also uses SMBX.
Pronouns: He/him/

Re: how do i make npc shoot stuff?

Postby Lucario » Thu Aug 05, 2021 8:55 am

I was trying to code a Huckit Crab, and that was also my roadblock (I followed carefully Enjl's tutorial). So I'm sorry, I cannot help you. :(

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: how do i make npc shoot stuff?

Postby Emral » Thu Aug 05, 2021 9:33 am

https://docs.codehaus.moe/#/reference/npc
If you look at the NPC.spawn function, you can see that it causes an NPC to spawn and returns the NPC in question.
local myNPC = NPC.spawn(id, x, y, section)
myNPC.speedX = 4

You can look at basegame code for (for example) the SMW bowser statue for reference.

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: how do i make npc shoot stuff?

Postby lolcode » Thu Aug 05, 2021 6:33 pm

Enjl wrote:
Thu Aug 05, 2021 9:33 am
https://docs.codehaus.moe/#/reference/npc
If you look at the NPC.spawn function, you can see that it causes an NPC to spawn and returns the NPC in question.
local myNPC = NPC.spawn(id, x, y, section)
myNPC.speedX = 4

You can look at basegame code for (for example) the SMW bowser statue for reference.
thanks

Added in 1 hour 39 minutes 50 seconds:
btw, is it posible for a projectile to be launched exactly at the player?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: how do i make npc shoot stuff?

Postby Emral » Fri Aug 06, 2021 12:57 am

Yeah, just get the distance vector between the player and npc locations and normalize it so that it always has a length of 1:
local firingDirection = vector(player.x - npc.x, player.y - npc.y):normalize()

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: how do i make npc shoot stuff?

Postby lolcode » Fri Aug 06, 2021 2:15 am

thank you


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 4 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari