Im trying to make an animation trigger on roblox studio, can someone tell me how? - roblox

So when I try touch the trigger, the thing I'm trying to animate doesn't so the animation, I tried the animation id, anything else, can someone send me a model that has this, it will be nice if you can.

I made this with the gui elements already done u fill in what u need.
local library = {}
local function onClicked(frame, gui)
gui:SetVisible(false)
gui:ClearAllChildren()
end
function library:Create(parent)
local frame = Instance.new("Frame")
frame.Size = UDim2.new(1, 0, 1, 0)
frame.BackgroundColor3 = Color3.new(1, 1, 1)
frame.BorderSizePixel = 0
local gui = Instance.new("TextLabel")
gui.Size = UDim2.new(0, 200, 0, 50)
gui.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
gui.Position = UDim2.new(0.5, -100, 0.5, -25)
gui.Text = "Click the Button"
gui.TextColor3 = Color3.new(1, 1, 1)
gui.TextXAlignment = Enum.TextXAlignment.Center
gui.TextYAlignment = Enum.TextYAlignment.Center
gui.Font = Enum.Font.SourceSans
gui.TextSize = 24
gui.Parent = frame
local button = Instance.new("TextButton")
button.Size = UDim2.new(0, 50, 0, 25)
button.BackgroundColor3 = Color3.new(1, 0, 0)
button.Position = UDim2.new(0.5, -25, 0.85, 0)
button.Text = "X"
button.TextColor3 = Color3.new(1, 1, 1)
button.Parent = frame
button.MouseButton1Click:Connect(function()
onClicked(frame, gui)
end)
frame.Parent = parent
return frame
end

Related

How to get SubtractAsync to fully slice off piece of the part

I'm trying to slice a part of this part, so that it matches the bottom part, and the method I'm trying is SubtractAsync.
When I do it however, the part gets sliced, but not so that the remaining part gets removed. Here's what I mean:
How do I edit my code to slice off the piece of the part?
My code:
local Brick = workspace.Brick
local Stack = Brick:Clone()
local TS = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, math.huge, true)
Stack.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + Brick.Size.Y, Brick.Position.Z - 55)
local tween = TS:Create(Stack, tweenInfo, {Position = Vector3.new(Stack.Position.X, Stack.Position.Y, Stack.Position.Z + (55 * 2))})
Stack.Parent = workspace
tween:Play()
game.ReplicatedStorage.PlaceDown.OnServerEvent:Connect(function()
tween:Pause()
local PartA = Instance.new("Part")
local PartB = Instance.new("Part")
PartA.Transparency = 1
PartB.Transparency = 1
PartA.Parent = workspace
PartB.Parent = workspace
PartA.Orientation = Vector3.new(-90, 0, 0)
PartB.Orientation = Vector3.new(-90, 0, 0)
PartA.Size = Vector3.new(15, 0.051, 15)
PartB.Size = Vector3.new(15, 0.051, 15)
PartA.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + 2.5, Brick.Position.Z - (Brick.Size.Z/2))
PartB.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + 2.5, Brick.Position.Z + (Brick.Size.Z/2))
PartA.Anchored = true
PartB.Anchored = true
local SlicedStack = Stack:SubtractAsync({PartA, PartB})
SlicedStack.Position = Stack.Position
SlicedStack.Parent = workspace
Stack:Destroy()
PartA:Destroy()
PartB:Destroy()
end)

tm_compass does not appear inside of graph

I'm trying to make a map of Europe using tmap and the eurostat package.
I want to add a compass and a scale bar to the map. However they don't appear inside the graph, but outside of the map, at the bottom. Does anyone know what I'm doing wrong? I want the compass at the left top of the map, and the scale bar at the right bottom.
countries = gisco_get_countries(
year = "2016",
epsg = "3035",
resolution = "3"
)
br = c(0,40,50,65,80,150)
tm_shape(countries, bbox = c(23, 14, 74, 55) * 10e4) +
tm_fill("#E0E0E0") +
tm_shape(nuts2.sf) +
tm_fill(
"fatal_inj_30day",
breaks = br,
style = "fixed",
palette = "Blues",
alpha = .7,
title = "Fatalities per million inhabitants \n(2018-2019)"
) +
tm_compass(position = c("left","top")) +
tm_scale_bar(position = c("right","bottom")) +
tm_shape(countries) +
tm_borders(lwd = .25) +
tm_layout(
bg.color = "#F2F2F2",
outer.bg.color = "white",
legend.bg.color = "white",
legend.frame = "black",
legend.title.size = 0.8,
inner.margins = c(0, 0, 0, 0),
outer.margins = c(0, 0, 0, 0),
frame = TRUE,
frame.lwd = 0,
attr.outside = TRUE,
legend.position = c("right", "top"),
main.title = "Note: regions with 10 fatalities or less are not included in the Figure",
main.title.position = "left",
main.title.size = 0.7
)

Part Size seems to be ignored

I have a part, created with
local p = Instance.new("Part")
p.Size = Vector3.new(2, 2, 2)
That part uses a mesh like
local m = Instance.new("SpecialMesh", p)
m.MeshType = Enum.MeshType.FileMesh
m.MeshId = "rbxassetid://7974596857"
which is a cube with rounded corners that I created in blender
When I put those beside each other, it seems like the Size property actually is ignored.
Why?
size 2
p1.Position = Vector3.new(0, 0, 0)
p1.Size = Vector3.new(2, 2, 2)
p2.Position = Vector3.new(5, 5, 0)
p2.Size = Vector3.new(2, 2, 2)
size 5
p1.Position = Vector3.new(0, 0, 0)
p1.Size = Vector3.new(5, 5, 5)
p2.Position = Vector3.new(5, 5, 0)
p2.Size = Vector3.new(5, 5, 5)
That's because special meshes have their own scaling property. If possible, use a MeshPart instead.

SceneKit SCNPhysicsVehicle wheels point toward centre of vehicle

I'm trying to get the SceneKit Physics Vehicle demonstration from WWDC working using Swift 2 and also the Scene Editor and .scnassets. I'm adapting this port of the demo to Swift 1.
I've also been experimenting with some of the Model I/O functions, such as SkyBox and normal map generation.
Everything works fine, except that the wheels are rotated 180 degrees around their steering axes, so that the hubcaps point in towards the centre of the car:
Hubcaps pointing inwards
The wheels spin in the right direction, and the car can be driven and steered fine, but it just looks very weird (and the left-right wheelbase is narrower than it should be).
If I comment out the SCNPhysicsVehicle and SCNPhysicsVehicleWheel code, so that it's just geometry with a physics body for the chassis, the geometry displays correctly, with the wheel hubs pointing outward:
Hubcaps pointing outwards
I've tried rotating the wheelnodes using wheelnode0.rotation before defining the SCNPhysicsVehicleWheel, but it has no effect.
I tried reversing the wheel axles with wheel0.axle = SCNVector3(x: 1,y: 0,z: 0) and that makes the wheels face the right way, hubcap outwards, (and they still spin the right way), but the car moves backwards (ie the opposite direction to how the wheels are spinning).
It feels like something weird is going on with how axes are being translated, but I can't figure what it is. I've tried it with the original .dae model from the Apple demo, as well as converted to an .scn file. I've tried it inside and outside an .scnassets folder (in case it was something to do with scnassets auto correction of up axis). I tried inverting the wheel steering axes, but that just resulted in the wheels pointing up in the air.
Here's my vehicle creation function, with all the stuff I've tried commented out. Full repo is here: https://github.com/Utsira/SCNPhysicsVehicle-test. Can anyone see what's going wrong here? Thanks in advance.
func setupCar() -> SCNNode {
let carScene = SCNScene(named: "art.scnassets/rc_car.scn") //rc_car.dae
let chassisNode = carScene!.rootNode.childNodeWithName("rccarBody", recursively: true)!
chassisNode.position = SCNVector3Make(0, 10, 30)
//chassisNode.rotation = SCNVector4(0, 1, 0, CGFloat(M_PI))
let body = SCNPhysicsBody.dynamicBody()
body.allowsResting = false
body.mass = 80
body.restitution = 0.1
body.friction = 0.5
body.rollingFriction = 0
chassisNode.physicsBody = body
scnScene.rootNode.addChildNode(chassisNode)
//getNode("rccarBody", fromDaePath: "rc_car.dae")
let wheelnode0 = chassisNode
.childNodeWithName("wheelLocator_FL", recursively: true)!
let wheelnode1 = chassisNode
.childNodeWithName("wheelLocator_FR", recursively: true)!
let wheelnode2 = chassisNode
.childNodeWithName("wheelLocator_RL", recursively: true)!
let wheelnode3 = chassisNode
.childNodeWithName("wheelLocator_RR", recursively: true)!
//wheelnode0.geometry!.firstMaterial!.emission.contents = UIColor.blueColor()
// SCNTransaction.begin()
// wheelnode0.rotation = SCNVector4(x: 0, y: 1, z: 0, w: Float(M_PI)) //CGFloat(M_PI)
// wheelnode1.rotation = SCNVector4(x: 0, y: 1, z: 0, w: Float(M_PI))
// wheelnode2.rotation = SCNVector4(x: 0, y: 1, z: 0, w: Float(M_PI))
// wheelnode3.rotation = SCNVector4(x: 0, y: 1, z: 0, w: Float(M_PI))
// SCNTransaction.commit()
// wheelnode0.eulerAngles = SCNVector3Make(0, Float(M_PI), 0 )
let wheel0 = SCNPhysicsVehicleWheel(node: wheelnode0)
let wheel1 = SCNPhysicsVehicleWheel(node: wheelnode1)
let wheel2 = SCNPhysicsVehicleWheel(node: wheelnode2)
let wheel3 = SCNPhysicsVehicleWheel(node: wheelnode3)
// wheel0.steeringAxis = SCNVector3Make(0, -1, 1) //wheels point up in the air with 0,1,0
// wheel1.steeringAxis = SCNVector3Make(0, -1, 1)
// wheel2.steeringAxis = SCNVector3Make(0, -1, 1)
// wheel3.steeringAxis = SCNVector3Make(0, -1, 1)
//
// wheel0.axle = SCNVector3(x: 1,y: 0,z: 0) //wheels face and spin the right way, but car moves in opposite direction with 1,0,0
// wheel1.axle = SCNVector3(x: 1,y: 0,z: 0)
// wheel2.axle = SCNVector3(x: 1,y: 0,z: 0)
// wheel3.axle = SCNVector3(x: 1,y: 0,z: 0)
// wheel0.steeringAxis = SCNVector3()
// var min = SCNVector3(x: 0, y: 0, z: 0)
// var max = SCNVector3(x: 0, y: 0, z: 0)
// wheelnode0.getBoundingBoxMin(&min, max: &max)
// let wheelHalfWidth = Float(0.5 * (max.x - min.x))
// var w0 = wheelnode0.convertPosition(SCNVector3Zero, toNode: chassisNode)
// w0 = w0 + SCNVector3Make(wheelHalfWidth, 0, 0)
// wheel0.connectionPosition = w0
// var w1 = wheelnode1.convertPosition(SCNVector3Zero, toNode: chassisNode)
// w1 = w1 - SCNVector3Make(wheelHalfWidth, 0, 0)
// wheel1.connectionPosition = w1
// var w2 = wheelnode2.convertPosition(SCNVector3Zero, toNode: chassisNode)
// w2 = w2 + SCNVector3Make(wheelHalfWidth, 0, 0)
// wheel2.connectionPosition = w2
// var w3 = wheelnode3.convertPosition(SCNVector3Zero, toNode: chassisNode)
// w3 = w3 - SCNVector3Make(wheelHalfWidth, 0, 0)
// wheel3.connectionPosition = w3
vehicle = SCNPhysicsVehicle(chassisBody: chassisNode.physicsBody!,
wheels: [wheel0, wheel1, wheel2, wheel3])
scnScene.physicsWorld.addBehavior(vehicle)
return chassisNode
}
I Found A Solution:
(but not the solution I hoped for)
My fix was to adjust the connectionPosition of "FrontLeftWheel", so much to the right, that it took the role of "FrontRightWheel".
And "FrontRightWheel", so much to the left, that it took the role of "FrontLeftWheel".
I also did this for the back.
Basically, where you have:
SCNVector3Make(wheelHalfWidth, 0, 0)
I replaced it with:
SCNVector3Make(wheelHalfWidth * 5.2, 0, 0)
However, you may have to fool around with the number "5.2" to match up with your COLLADA (.dae).
A Note:
Do Not forget to replace:
vehicle = SCNPhysicsVehicle(chassisBody: chassisNode.physicsBody!,
wheels: [wheel0, wheel1, wheel2, wheel3])
With:
vehicle = SCNPhysicsVehicle(chassisBody: chassisNode.physicsBody!,
wheels: [wheel1, wheel0, wheel3, wheel2])
This way, when you use car.wheels[0].You get the wheel you are expecting
I think your problem is that you are not setting the connection positions for each wheel. Apple's default ObjectiveC code is tricky to translate to swift.
wheel0.connectionPosition = SCNVector3FromFloat3(SCNVector3ToFloat3([wheel0Node convertPosition:SCNVector3Zero toNode:chassisNode]) + (vector_float3){wheelHalfWidth, 0.0, 0.0});
wheel1.connectionPosition = SCNVector3FromFloat3(SCNVector3ToFloat3([wheel1Node convertPosition:SCNVector3Zero toNode:chassisNode]) - (vector_float3){wheelHalfWidth, 0.0, 0.0});
wheel2.connectionPosition = SCNVector3FromFloat3(SCNVector3ToFloat3([wheel2Node convertPosition:SCNVector3Zero toNode:chassisNode]) + (vector_float3){wheelHalfWidth, 0.0, 0.0});
wheel3.connectionPosition = SCNVector3FromFloat3(SCNVector3ToFloat3([wheel3Node convertPosition:SCNVector3Zero toNode:chassisNode]) - (vector_float3){wheelHalfWidth, 0.0, 0.0});
These four lines translate (ignoring the repetition)
let wheel0Position = wheel0Node.convertPosition(SCNVector3Zero, to: chassisNode)
let vector0Float3 = vector_float3(wheel0Position.x, wheel0Position.y, wheel0Position.z) + vector_float3(wheelHalfWidth, 0,0)
wheel0.connectionPosition = SCNVector3(vector0Float3.x, vector0Float3.y, vector0Float3.z)
let wheel1Position = wheel1Node.convertPosition(SCNVector3Zero, to: chassisNode)
let vector1Float3 = vector_float3(wheel1Position.x, wheel1Position.y, wheel1Position.z) - vector_float3(wheelHalfWidth, 0,0)
wheel1.connectionPosition = SCNVector3(vector1Float3.x, vector1Float3.y, vector1Float3.z)
let wheel2Position = wheel2Node.convertPosition(SCNVector3Zero, to: chassisNode)
let vector2Float3 = vector_float3(wheel2Position.x, wheel2Position.y, wheel2Position.z) + vector_float3(wheelHalfWidth, 0,0)
wheel2.connectionPosition = SCNVector3(vector2Float3.x, vector2Float3.y, vector2Float3.z)
let wheel3Position = wheel3Node.convertPosition(SCNVector3Zero, to: chassisNode)
let vector3Float3 = vector_float3(wheel3Position.x, wheel3Position.y, wheel3Position.z) - vector_float3(wheelHalfWidth, 0,0)
wheel3.connectionPosition = SCNVector3(vector3Float3.x, vector3Float3.y, vector3Float3.z)
By adding or substracting vector_float3, the wheels are positioned in the right place.
Also, bear in mind that you can't scale the node in the scene or weird things may happen.
Encountered the same issue, my solution was to rotate all wheel nodes so the Y axis pointed down. I figured gravity is a downward force.

How to animate (moving by default) and inanimate (make stationary on tap) colliding objects

Hey Guys I am making a game using corona sdk and so needed help with the lus code. In this program there are bubbles floating across the screen and colliding with each either as well as with the walls of the screen.
I am using 'Collision Filter' for the collisions and the masking operation and it is working well. But in this game I want a bubble to continuously move unless and until it is tapped upon. I thought of using the frame animation to animate each bubble and then add a separate function that will make it stationary when tapped.
But the problem is that at a time only 1 program seems to wrok fine. So,
1) either the bubbles collide, fall down, bounce against wall and eventually rest down.
2) The bubbles continuously keep moving across the screen, without colliding against each other, and instead pass through the other bubbles
What should I do to animate and inanimate(on tapping that bubble) a colliding bubble.
My code is below,
borderCollisionFilter = { categoryBits = 1, maskBits = 2 } -- collides with (4 & 2) only
local borderBodyElement = { bounce=1.0, filter=borderCollisionFilter }
local borderTop = display.newRect( 0, 0, 480, 1 )
borderTop:setFillColor( 0, 0, 0, 0) -- make invisible
physics.addBody( borderTop, "static", borderBodyElement )
local borderBottom = display.newRect( 0, 318, 480, 1 )
borderBottom:setFillColor( 0, 0, 0, 0) -- make invisible
physics.addBody( borderBottom, "static", borderBodyElement )
local borderLeft = display.newRect( 0, 0, 1, 320 )
borderLeft:setFillColor( 0, 0, 0, 0) -- make invisible
physics.addBody( borderLeft, "static", borderBodyElement )
local borderRight = display.newRect( 480, 1, 1, 320 )
borderRight:setFillColor( 0, 0, 0, 0) -- make invisible
physics.addBody( borderRight, "static", borderBodyElement )
--BUBBLES
local bubbleCollisionFilter = { categoryBits = 2, maskBits = 7 }
bubble = {bounce=0.94, radius=18,filter = bubbleCollisionFilter }
local bubble1 = display.newImage( "bubble.png", 50, 50 )
physics.addBody( bubble1, bubble )
local bubble2 = display.newImage( "bubble.png", 100, 230 )
physics.addBody( bubble2, bubble )
local bubble3 = display.newImage( "bubble.png", 180, 200 )
physics.addBody( bubble3, bubble )
local bubble4 = display.newImage( "bubble.png", 90, 30 )
physics.addBody( bubble4, bubble )
--MINIONS
minionCollisionFilter = { categoryBits = 4, maskBits = 2 }
minionBodyElement = { bounce=0.8, filter=minionCollisionFilter }
local c1 = display.newImage("str-minion-small.png")
c1.isVisible=false
physics.addBody( c1, "static", minionBodyElement )
local c2 = display.newImage("str-minion-mid.png")
c2.isVisible=false
physics.addBody( c2, "static", minionBodyElement )
local c3 = display.newImage("str-minion-big.png")
c3.isVisible=false
physics.addBody( c3, "static", minionBodyElement )
--SPAWNING
local function spawnDisk( event )
local phase = event.phase
local volumeBar = display.newLine( 0, 0, 1, 0 )
volumeBar.y = 400
volumeBar.x = 20
local v = 20*math.log(r:getTunerVolume())
local MINTHRESH = 30
local LEFTMARGIN = 20
local v2 = MINTHRESH + math.max (v, -MINTHRESH)
v2 = (display.contentWidth - 1 * LEFTMARGIN ) * v2 / MINTHRESH
volumeBar.xScale = math.max ( 20, v2 )
local l = volumeBar.xScale
local cnt1 = 0
local cnt2 = 0
local cnt3 = 0
local ONE =1
local val = event.numTaps
if "ended" == phase then
if l > 50 and l <=150 then
c1.x=math.random( 10, 450 )
c1.y=math.random( 10, 300 )
physics.addBody( c1, { density=1, radius=10.0 } )
c1.isVisible=true
cnt1= cnt1+ ONE
return c1
elseif l > 100 and l <=250 then
c2.x=math.random( 10, 450 )
c2.y=math.random( 10, 300 )
physics.addBody( c2, { density=2, radius=30.0 } )
c2.isVisible=true
cnt2= cnt2+ ONE
return c2
elseif l >=250 then
c3.x=math.random( 40, 450 )
c3.y=math.random( 40, 300 )
physics.addBody( c3, { density=2, radius=50.0 , bounce=0.0 } )
c3.isVisible=true
cnt3= cnt3+ ONE
return c3
end
end
end
buzzR:addEventListener( "touch", spawnDisk ) --
touch the Button to create minions
Listen for tap events and set objects to static:
http://developer.anscamobile.com/reference/index/bodybodytype
ADDITION: I hadn't bothered to run your code because you claimed the collision masking worked. Now that I actually have tried to run it, I got an error immediately.
First off, you need to require "physics" at the top of your code:
local physics = require("physics")
Then there is a timeout error just a few lines down because you didn't start the physics simulation. The second line of your code should be:
physics.start()
Now I'm going to assume those two lines are actually at the top of your code but you simply didn't paste them here, because I can't imagine you would write a hundred lines of code without ever running it.
However that still leaves more errors. Like, at the bottom of your code it references buzzR but there's no object buzzR defined anywhere.
Please either post code that works or say that you don't have code that works. Sorting through this mess is frustrating.
I have done one application to help with collision masking in Corona SDK, for free of course.
http://developer.anscamobile.com/forum/2011/09/12/coolmasking-take-total-control-over-collision-masking