Sohjiro Posted September 20, 2019 Share Posted September 20, 2019 so I'm currently using this code to spawn a prefab which I got from the pigking code local prefab = SpawnPrefab(prefabname) prefab.Transform:SetPosition(inst.Transform:GetWorldPosition()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) / DEGREES local speed = math.random() * 4 + 2 angle = (angle + math.random() * 60 - 30) * DEGREES prefab.Physics:SetVel(speed * math.cos(angle), math.random() * 2 + 8, speed * math.sin(angle)) what I want to be able to do is give the user of my mod the ability to pick the direction via 45 degree angles that the item spawns at but after playing with it for quite a while I can't seem to figure out how to make it work I don't understand what the Physics:SetVel(x,y,z) needs to pick its direction Link to comment Share on other sites More sharing options...
Serpens Posted September 21, 2019 Share Posted September 21, 2019 (edited) can you describe more what the result should look like? You say someone should be able to choose a direction, but how?! with a popup box asking you where to spawn it? With an action the character did in a specific direction? Or what? And how do you want the item to be "spawned" , simply appears eg. left to the player. Or do you want to "fling" it, like when you get gold from the pigking? Edited September 21, 2019 by Serpens Link to comment Share on other sites More sharing options...
Sohjiro Posted September 21, 2019 Author Share Posted September 21, 2019 (edited) like I want to include in the mod settings a degree option so they can pick the angle ie (0, 45, 90, 135, 180, 225, 270, 315) that the item spawns at and I want it to fling kinda like the pig king with a little bit a variance. Edited September 21, 2019 by Sohjiro Link to comment Share on other sites More sharing options...
Serpens Posted September 21, 2019 Share Posted September 21, 2019 (edited) ok, I already used the same code in my questapimod, looks like this: local function launchitem(item, angle) local speed = math.random() * 4 + 2 angle = (angle + math.random() * 60 - 30) * DEGREES item.Physics:SetVel(speed * math.cos(angle), math.random() * 2 + 8, speed * math.sin(angle)) end local function SpawnDrop(inst, lootprefab, player) local x, y, z = inst.Transform:GetWorldPosition() y = 4.5 local angle if player ~= nil and type(player)=="table" and player:IsValid() then angle = 180 - player:GetAngleToPoint(x, 0, z) else local down = TheCamera:GetDownVec() angle = math.atan2(down.z, down.x) / DEGREES end local item = SpawnPrefab(lootprefab) if item ~= nil then item.Transform:SetPosition(x, y, z) launchitem(item, angle) end end but I never needed a specific angle, so I also have to guess... Did you already try to replace the very first angle variable with your custom angle, or the second? If you want a specific angle, you should remove the "math.random" from the angle formula, since it adds randomness. Edited September 21, 2019 by Serpens Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now