So, For Context im trying to emulate kind of like throwing an axe, when you throw an axe it spins and spins and spins vertically.However, I got the spinning part right but the axis that is at, is not right the axe it should be facing vertically not facing you, i will post a gyazo link just so u can see how it spins right now. https://gyazo.com/99eaa8c1b5b3ce22205148509e115b14
Ive tried a couple things, ive tweend it, i thought that would work, as tweening it i can do it infinitley, But the result was it being still. I also tried pivoting it, But because of my courtine. Sometimes it wouldnt even go through
Heres The roblox code
local function ZodiacMove(plr,Mouse)
local TestingCourotine = coroutine.create(function(Handle)
while true do RunService.Stepped:Wait()
print(Handle)
Handle.CFrame = Handle.CFrame * CFrame.Angles(0,0,math.rad(10))
if Handle.Parent == nil then break end
end
print('the axe has vanished :sob:')
end)
local ZodiacProjectile = game:GetService("ReplicatedStorage").Axe:Clone()
local Handle = ZodiacProjectile:FindFirstChild("Blade")["Blade Tip"]
print(Handle)
local ZodiacProjectilePivot = ZodiacProjectile:GetPivot()
ZodiacProjectile:PivotTo(ZodiacProjectilePivot * CFrame.new(math.rad(10),0,0))
coroutine.resume(TestingCourotine,Handle)
---TweenInfoGoals.CFrame = Handle.CFrame * CFrame.Angles(0,0,math.rad(360))
--local ZodiacProjectileTween = TweenService:Create(Handle, tweenInfo,TweenInfoGoals)
--ZodiacProjectileTween:Play()
local OverParams = OverlapParams.new()
OverParams.FilterType = Enum.RaycastFilterType.Blacklist
OverParams.FilterDescendantsInstances = {workspace.Baseplate, plr.Character, plr.Character:GetChildren()}
local HumanoidRootPart = plr.Character:WaitForChild("HumanoidRootPart")
local BV = Instance.new("BodyVelocity")
BV.Parent = Handle
ZodiacProjectile.Parent = HumanoidRootPart
BV.Velocity = HumanoidRootPart.CFrame.LookVector * 100
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
ZodiacProjectile:PivotTo( HumanoidRootPart.CFrame * CFrame.new(0, 0, -1))
Debris:AddItem(ZodiacProjectile,2)
end```
Related
I add a mesh to follow the player where ever he goes. But the mesh is lagging a bit when the player runs. I understand that it is not rendering quickly enough, but anyone know how to add a mesh without it lagging?
local humanoidRootPart = character:WaitForChild('HumanoidRootPart')
local backpackItemWorkspace = game.ReplicatedStorage.Meshes[pet.Name]:Clone()
backpackItemWorkspace.Parent = game.Workspace.CurrentPets
RunService.Stepped:Connect(function()
local location = humanoidRootPart.CFrame
backpackItemWorkspace.CFrame = location * CFrame.new(2, 2, 3)
end)
Connect the mesh and rootpart using a weld, so you dont need to use RunService to move the mesh everytime.
local humanoidRootPart = character:WaitForChild('HumanoidRootPart')
local backpackItemWorkspace = game.ReplicatedStorage.Meshes[pet.Name]:Clone()
backpackItemWorkspace.Parent = game.Workspace.CurrentPets
function attach(hroot, mesh)
local weld = Instance.new("WeldConstraint", mesh)
local location = hroot.CFrame
mesh.CFrame = location + Vector3.new(2, 2, 3)
weld.Part0 = hroot
weld.Part1 = mesh
return weld
end
attach(humanoidRootPart, backpackItemWorkspace)
-- please comment if it makes any errors
Ok, for others struggling with having a pet(mesh) follow you smoothly and always stay on your back. I have now spent several hours on this subject and finally got it to work. This is how you do it:
local character = player.Character
local humanoidRootPart = character:WaitForChild('HumanoidRootPart')
//where you copy you pet from
local backpackItemWorkspace = game.ReplicatedStorage.Meshes[pet.Name]:Clone()
//where you keep your pets in the workspace
backpackItemWorkspace.Parent = game.Workspace.CurrentPets
//call the function for attaching the pet
attachPet(backpackItemWorkspace, character, humanoidRootPart)
function attachPet (pet, char, humanoidRootPart)
local focusPart = humanoidRootPart
local newPet = pet
local z = -5
local x = 1
local bodyPos = Instance.new("BodyPosition")
bodyPos.Parent = newPet
bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = newPet
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
while wait() do
bodyPos.Position = focusPart.Position + focusPart.CFrame.LookVector * z + focusPart.CFrame.RightVector * x
bodyGyro.CFrame = focusPart.CFrame
end
end
Also when you unequip a pet you have to Destroy it from where you store it. In my case I store them in a folder on the player which I call collectionInventory.
local collectionInventory = player:WaitForChild("CollectionInventory")
collectionInventory[petName]:Destroy()
Hope this save anybody else from wasting several hours with research. Even though you will probably learn a lot from those "wasted hours" ;)
I tried to make an item spawn every 60 seconds and in one of two locations, but when I tried to use vector3 it didn't spawn in the location of the "spawnplace1" or "spawnplace2", but it spawned ontop of the roka being copied and didn't move. Also I don't think I can hold the copied roka's either. Here's the code!
local roka = workspace["Rokakaka Fruit"]
local itemspawns = workspace.ItemSpawnLocals
local itemspawn1 = itemspawns["Item Spawn 1"]
local itemspawn2 = itemspawns["Item Spawn 2"]
local place1 = itemspawn1.Position
local place2 = itemspawn2.Position
wait(60)
local spawnplace1 = math.random(1,2)
local spawnplace2 = math.random(1,2)
if spawnplace1 == 1 then
roka2 = roka:Clone()
roka2.Parent = workspace
local roka2handle = roka2.Handle
roka2handle.Position = Vector3.new(itemspawn1)
elseif spawnplace1 == 2 then
roka2 = roka:Clone()
roka2.Parent = workspace
local roka2handle = roka2.Handle
roka2handle.Position = Vector3.new(itemspawn2)
end
print(spawnplace1)
print(spawnplace2)
The Vector3 holds coordinates of a point in 3D space. You have only provided 1 of 3 pieces of information in the constructor. To construct a Vector3, you need to provide the Y and Z axes as well, like this :
roka2handle.Position = Vector3.new(1, 2, 3)
But you don't need to explicitly create a Vector3 to get your code working. You can just assign the positions of the spawn locations to your newly created fruit, and that should do the trick. This way, you can add lots more spawn locations, and you don't need to update the script each time.
-- grab some things from the workspace
local roka = workspace["Rokakaka Fruit"]
local itemSpawns = workspace.ItemSpawnLocals
-- choose a random spawn location
local spawnLocations = itemSpawns:GetChildren()
local spawnNumber = math.random(1, #spawnLocations)
local spawnPosition = spawnLocations[spawnNumber].Position
-- spawn and move a new fruit to one of the spawn locations
roka2 = roka:Clone()
roka2.Parent = workspace
local roka2handle = roka2.Handle
roka2handle.Position = spawnPosition
-- debug
print("spawning fruit at : ", spawnPosition)
As a side note, if roka2 is a Model, you may want to consider using roka2:SetPrimaryPartCFrame( CFrame.new(spawnPosition)) to move it around.
I've been practicing tweening on Lua and I'm struggling to understand why I can't get my platform to move back and fourth between a start and an end platform. First I'll show the code
-- Starting Variables
local TweenService = game:GetService("TweenService")
local group = game.Workspace.MovingPlatform
-- Group Variables
local part = group.Platform
local start = group.Check1
local finish = group.Check2
-- Vectors
local destination = Vector3.new(start.Position.x,start.Position.y, start.Position.z)
-- Platform Tween Info
local info = TweenInfo.new(
1, --Length (seconds)
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
-1,--Times To Be Repeated
true,
0 --Delay
)
-- Where the destination is
local Goals = {
Position = Vector3.new(destination)
}
-- Makes it go
local MovePart = TweenService:Create(part, info, Goals)
MovePart:Play()
-- Debugging
local startPosition = Vector3.new(start.Position.x, start.Position.y, start.Position.z)
local endPosition = Vector3.new(finish.Position.x, finish.Position.y, finish.Position.z)
local partPosition = Vector3.new(part.Position.x, part.Position.y, part.Position.z)
while true do
print("Start Position: "..tostring(startPosition))
print("Destination: "..tostring(destination))
print("End Position: "..tostring(endPosition))
print("Platform Position: "..tostring(partPosition))
print("--------------")
wait(3)
end
The platform will move once and then start bugging out and going anywhere and eventually will rest on the floor moving back and fourth but not at the correct location. I've tried debugging to see if the positioning of any of my parts were somehow changing but everything stayed the same. Maybe I'm not logging the positions correctly but nonetheless any hints at what I could be doing wrong?
You might want to try using CFrame instead of Position when moving things.
Also, Part.Position is a Vector3 so there's no point in creating a new Vector3 for a Vector3.
Try something like this:
-- Starting Variables
local TweenService = game:GetService("TweenService")
local group = game.Workspace.MovingPlatform
-- Group Variables
local part = group.Platform
local start = group.Check1
local finish = group.Check2
-- Set the platform part to start at Check1
part.CFrame = start.CFrame
-- Platform Tween Info
local info = TweenInfo.new(
1, --Length (seconds)
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
-1,--Times To Be Repeated
true,
0 --Delay
)
-- Where the destination is
local Goals = {
CFrame = finish.CFrame -- We want it to end at the finish part's position
}
-- Makes it go
local MovePart = TweenService:Create(part, info, Goals)
MovePart:Play()
My project structure is following:
--Shooter
----sprites
------background.png
------player.png
------zombie.png
----units
------player.lua
------zombie.lua
----main.lua
----load.lua
----update.lua
----draw.lua
And my main.lua will have the following:
local Bullet = require("units.bullet")
local Player = require("units.player")
local Zombie = require("units.zombie")
require("load")
require("update")
require("draw")
require("functions")
love.window.setTitle("Shooter")
function love.load()
Load()
end
function love.update(dt)
Update(dt)
end
function love.draw()
Draw()
end
For example, bullet.lua:
local Bullet = {}
bulletSprite = love.graphics.newImage('sprites/bullet.png')
function Bullet.create()
local newBullet = {
pos = {},
speed = 10,
sprite = bulletSprite,
direction = 0,
dead = false
}
return setmetatable(newBullet, {__index = Bullet})
end
function Bullet:setPos(x, y)
self.pos.x = x
self.pos.y = y
end
function Bullet:setDirection(angle)
self.direction = angle
end
function Bullet:move(dt)
local distance = self.speed * dt * 60
self.pos.x = self.pos.x + math.cos(self.direction) * distance
self.pos.y = self.pos.y + math.sin(self.direction) * distance
end
function spawnBullet(bullets, player)
local newBullet = Bullet.create()
newBullet:setPos(player.pos.x, player.pos.y)
newBullet.direction = player.angle
table.insert(bullets, newBullet)
end
The problem is that none of the files in units folder will load properly. From the error log I can see that it tries to search for bullet.lua in the root directory and then various love2d and lua libraries.
I have tried various things like require("./units/bullet") or replace / with . but so far, no luck.
Extracting those files from the units folder into root folder will work. Loading images from sprites folder works, however (for example love.graphics.draw(sprites.background, 0, 0)).
Any help?
I found out the problem was that while my main.lua had correct requires, my update file didn't.
Two things come to mind.
Make Sure LUA_PATH is set to your project directory
add return Bullet, return Player and so on... into each module you have created
I'm a new programmer with no much experience; as a good noob it's very probable that the next code lines you will see may show a wide number of errors or imprecisions thus I'm excusing myself ahead of time.
So, the situation is the following:
Lately I'm interfacing with a new programming language (new for me obviously) that is LUA (using corona sdk). I approached the language writing simple codes.
Now I'm trying to execute a program that has simply to display two rectangles affected by the gravity. When I try to emulate the applicarion on my PC with CORONA it works without any kind of problem; after having built it for android OS, having installed it on my phone and having run it the result is an error message that is the following:
This is the error message:
"main.lua.35: ERROR: table expected. If this is a function call you might have used '.' instead of ':' "
This is the code:
local physics = require("physics")
physics.start()
local _W = display.contentWidth
local _H = display.contentHeight
local platform = display.newRect(
--x =
_W/2,
--y =
_H/2,
--width =
100,
--height =
100
)
platform.surfaceType = "rectangle"
local myImage = display.newImage("icon.png",_W/2,50)
local iconCollision = {
friction = 0.0, --attrito
bounce = 0.0, --rimbalzo (forse)
isSensor = true --collisione con altri oggetti
}
physics.addBody(platform,"static")
physics.addBody(myImage,"dynamic",iconCollision) --this is line 35
platform.collision = onCollision
local function onGyroscopeDataReceived( event )
local deltaRadians = event.zRotation * event.deltaTime
local deltaDegrees = deltaRadians * (180/math.pi)
end
local function dragImage(event)
local t=event.target
print(event.phase)
if(event.phase == "moved") then
t.x = event.x
t.y = event.y
end
end
local function onCollision( event )
if ( event.phase == "began" ) then
print("toccato")
end
end
if system.hasEventSource( "gyroscope" ) then
Runtime:addEventListener( "gyroscope", onGyroscopeDataReceived )
end
Runtime:addEventListener("collision",onCollision)
myImage:addEventListener("touch",dragImage)
I will be very grateful with those who will try to help me.
I think maybe event.zRotation is null. On iOS, you can use the appropriate UIRequiredDeviceCapabilities. In building.settings add this UIRequiredDeviceCapabilities = { ["gyroscope"]=true }. On Android set the usesFeatures = { { name="android.hardware.sensor.gyroscope", required=true } }.
Look for the name of the image on the disk , "icon.png", uppercase and lowercase matters, on Android device it could lead to errors, not showed in simulators.
If it doesn't load myImage:addEventListener would display an errore, maybe the one you see.
Also try to exclude pieces of code and then run the program on device back. I found difference with simulator that way.