Positioning in 3D Help

Is there anyway to update an entity’s position each and every frame to be in the exact same position as another entity??

Thanks in advance :slight_smile:

Not sure why you want to do that, but run this and tap the screen to move the position of the blue ball to the same position as the red ball. If you want to do that every frame, then instead of the line of code in touched, it would be in draw.

viewer.mode=FULLSCREEN

function setup()
    assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
    size=1
    fill(255)
    scene = craft.scene()
    skyMaterial=scene.sky.material
    skyMaterial.sky=color(0, 62, 255, 255)
    skyMaterial.horizon=color(99, 255, 0, 255)
    scene.sun.rotation=quat.eulerAngles(20,45,-30)
    createObjects()
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 30, 0, 200)
end

function createObjects()
    sphere1=scene:entity()
    s1=sphere1:add(craft.rigidbody,KINEMATIC)
    s1.restitution=1
    sphere1.position=vec3(0,5,0)
    sphere1:add(craft.shape.sphere,size)
    sphere1.model = craft.model.icosphere(size,2)
    sphere1.material = craft.material(asset.builtin.Materials.Specular)
    sphere1.material.diffuse=color(255,0,0)
    
    sphere2=scene:entity()
    s2=sphere2:add(craft.rigidbody,KINEMATIC)
    s2.restitution=1
    sphere2.position=vec3(0,-5,0)
    sphere2:add(craft.shape.sphere,size)
    sphere2.model = craft.model.icosphere(size,2)
    sphere2.material = craft.material(asset.builtin.Materials.Specular)
    sphere2.material.diffuse=color(0,0,255)
end

function draw()
    update(DeltaTime)
    scene:draw()	
end

function update(dt)
    scene:update(dt)
end

function touched(t)
    if t.state==BEGAN then
        sphere2.position=vec3(sphere1.x,sphere1.y,sphere1.z)
    end
end

@dave1707, I tried it on my code and it did not work. Here’s my code:

– Free Roam Craft Game

texChoice = math.random(1, 3)
houseChoice = math.random(1, 4)

function CreateGround(x, z)
local ground = scene:entity()
gBody = ground:add(craft.rigidbody, STATIC)
ground.model = craft.model.cube(vec3(4, 4, 4))
ground.material = craft.material(asset.builtin.Materials.Specular)
ground.material.map = readImage(asset.builtin.Blocks.Gravel_Dirt)
ground.x = x
ground.y = -3.125
ground.z = z
end

function CreateFloor(x, y, z)
local floor = scene:entity()

floor.model = craft.model.cube(vec3(4, 4, 4))
floor.material = craft.material(asset.builtin.Materials.Specular)
floor.material.map = readImage(asset.builtin.Blocks.Wood)
floor.x = x
floor.y = y
floor.z = z

end

function CreateWalls(x, y, z, e)
local wall = scene:entity()

wall.model = craft.model.cube(vec3(4, 4, 1))
wall.material = craft.material(asset.builtin.Materials.Specular)
wall.material.map = readImage(asset.builtin.Blocks.Brick_Red)
wall.eulerAngles = e
wall.x = x
wall.y = y
wall.z = z

end

function MakeFurniture()
local bed = scene:entity()
bed.model = craft.model(asset.documents.Dropbox.bedDouble_obj)
bed.eulerAngles = vec3(0, 0, 0)
bed.x = -22.5
bed.y = -1.140
bed.z = 6
bed.scale = vec3(20, 20, 20) / 8

local lounge = scene:entity()
lounge.model = craft.model(asset.documents.Dropbox.loungeDesignSofa_obj)
lounge.x = -19.2
lounge.y = -1.140
lounge.z = 7
lounge.scale = vec3(20, 20, 20) / 8

local bookshelf = scene:entity()
bookshelf.model = craft.model(asset.documents.Dropbox.bookcaseClosed_obj)
bookshelf.eulerAngles = vec3(0, -90, 0)
bookshelf.x = -24
bookshelf.y = -1.140
bookshelf.z = 4
bookshelf.scale = vec3(20, 20, 20) / 8

local tv = scene:entity()
tv.model = craft.model(asset.documents.Dropbox.televisionVintage_obj)
tv.position = vec3(-21.2, -1.140, 4)
tv.scale = vec3(40, 40, 40) / 8
tv.eulerAngles = vec3(0, -200, 0)

end

function CreateScenery()
local sign = scene:entity()
sign.model = craft.model(asset.documents.Dropbox.signpost_obj)
sign.position = vec3(1, -1.140, 0)
sign.eulerAngles = vec3(0, 300, 0)
sign.scale = vec3(5, 5, 5) / 8

local flatRock = scene:entity()
fBody = flatRock:add(craft.rigidbody, DYNAMIC)
flatRock.model = craft.model(asset.documents.Dropbox.rockFlatGrass_obj)
flatRock.position = vec3(-2, -1.140, 4)
flatRock.eulerAngles = vec3(0, 0, 0)
flatRock.scale = vec3(5, 5, 5) / 8

local tent = scene:entity()
tBody = tent:add(craft.rigidbody, DYNAMIC)
tent.model = craft.model(asset.documents.Dropbox.tentClosed_obj)
tent.position = vec3(1.5, -1.140, 7)
tent.eulerAngles = vec3(0, 270, 0)
tent.scale = vec3(7, 7, 7) / 8  

end

function MakeHouses(x, z, e)
local house = scene:entity()
hBody = house:add(craft.rigidbody, DYNAMIC)
if houseChoice == 1 then
house.model = craft.model(asset.documents.Dropbox.house_type01_obj)
end

if houseChoice == 2 then
    house.model = craft.model(asset.documents.Dropbox.house_type02_obj)
end

if houseChoice == 3 then
    house.model = craft.model(asset.documents.Dropbox.house_type03_obj)
end

if houseChoice == 4 then
    house.model = craft.model(asset.documents.Dropbox.house_type04_obj)
end
house.x = x
house.y = -1.140
house.z = z
house.eulerAngles = e
house.scale = vec3(32, 32, 32) / 8
hBody.restitution = 1

end

function MakeBlock(p, e)
local block = scene:entity()
block.model = craft.model.cube(vec3(1, 1, 1))
block.material = craft.material(asset.builtin.Materials.Specular)
if texChoice == 1 then
block.material.map = readImage(asset.builtin.Blocks.Brick_Grey)
end

if texChoice == 2 then
    block.material.map = readImage(asset.builtin.Blocks.Dirt_Grass)
end

if texChoice == 3 then
    block.material.map = readImage(asset.builtin.Blocks.Greystone_Ruby_Alt)
end
block.position = p
block.eulerAngles = e

end

function DrawSword()

end

function bounceAround()
if rotation >= 90 then
tween(1, rotation, {0}, tween.easing.bounceInOut)
end

if rotation <= -90 then
    tween(1, rotation, {0}, tween.easing.bounceInOut)
end

end

function setup()
– Create a new craft scene
scene = craft.scene()
parameter.watch(“scene.camera.y”)
parameter.watch(“transTweening”)
scene.physics.gravity = vec3(0, -1, 0)
sunny = readText(asset.builtin.Environments.Sunny)
night = readText(asset.builtin.Environments.Night)
env = craft.cubeTexture(json.decode(sunny))
scene.sky.material.envMap = env
scene.sun.rotation = quat.eulerAngles(25, 125, 0)
setFlying = false
time = 0
rotation = 0
rotation2 = 0
startView = true
BuildMode = false
grav = false
ROOM = false
jumping = false
jumpPressed = false
housePressed = false
drawPressed = false
drawSword = false
walkPlaying = false
transTweening = false
tS = {x = 0, y = 0}
trS = {x = 0, y = 0}
bP = {x = scene.camera.x, y = 0, z = 0}
tpS = {x = 0, y = 0}
alphaTapChannel = {x = 96, y = 0}
cameraX = scene.camera.x
cameraZ = scene.camera.z
jumpForce = 0
voiceSpeech = 1
walkSound = 0
roomColor = {x = 0, y = 0, z = 0}
viewer.mode = FULLSCREEN

if ROOM == false then
-- Create a new entity
local e = scene:entity()
body = e:add(craft.rigidbody, DYNAMIC)

if grav == true then
    scene.physics.gravity = vec3(0, -1, 0)
end

if grav == false then
    scene.physics.gravity = vec3(0, 0, 0)
end


e.model = craft.model(asset.builtin.Blocky_Characters.Robot) 
e.x = -3
e.y = -1
e.z = 0
e.scale = vec3(1, 1, 1) / 8
e.eulerAngles = vec3(0, 180, 0)

CreateGround(0, 0)
CreateGround(0, 4)
CreateGround(0, 8)
CreateGround(0, -4)
CreateGround(0, -8)
CreateGround(4, 0)
CreateGround(4, 4)
CreateGround(4, 8)
CreateGround(4, -4)
CreateGround(4, -8)
CreateGround(-4, 0)
CreateGround(-4, 4)
CreateGround(-4, 8)
CreateGround(-4, -4)
CreateGround(-4, -8)
CreateScenery()

if houseChoice == 1 then
    MakeHouses(6, 3, vec3(0, 270, 0))
end

if houseChoice == 2 then
    MakeHouses(4.85, 3, vec3(0, 270, 0))
end

if houseChoice == 3 then
    MakeHouses(4, 3, vec3(0, 270, 0))
end

if houseChoice == 4 then
    MakeHouses(5.5, 3, vec3(0, 270, 0))
end
    
      
    
    
scene.camera.z = -4
scene.camera.x = -3
camBody = scene.camera:add(craft.rigidbody, STATIC)
cameraSettings = scene.camera:get(craft.camera)
scene.camera:add(craft.shape.capsule, 0.5, 1.0)
camBody.restitution = 1
    



speech.voice = speech.voices[13]
speech.volume = voiceSpeech
speech.say("Welcome to Peaceful Land! Feel free to leave anytime!") 

    

tween(1000, body, {linearVelocity = vec3(0, 1000, 0)})    


music(asset.downloaded.A_Hero_s_Quest.In_the_City, true, voiceSpeech)


end

if ROOM == true then
    
end

end

function CreateRoomText()
font(“Courier-BoldOblique”)
fontSize(tS.x)
fill(255, 0, 21)
rotate(tS.x / 10)
text(“Your Room”, WIDTH/2 - 150, WIDTH/2 + 100)
fontSize(tS.y)
text(“Relax and rest!”, WIDTH/2 - 150, WIDTH/2 + 40)
end

function makeLoadTransition()
fill(0)
ellipse(WIDTH/2, WIDTH/2, trS.x)
end

function CreateTapEffect(x, y)
fill(255, alphaTapChannel.x)
ellipse(x, y, tpS.x)
end

function MakeBlaster()

end

function update(dt)
– Update the scene (physics, transforms etc)
scene:update(dt)
end

function touched(touch)

if touch.state == MOVING and touch.deltaY > 0 then
    scene.camera.z = scene.camera.z + 0.04
    scene.camera.x = scene.camera.x + rotation / 816
    
    
    
    if voiceSpeech <= 1  and scene.camera.z >= -6 and scene.camera.x <= -4 then
    voiceSpeech = voiceSpeech + 0.01
    music.volume = voiceSpeech
    end
    
   
end


    
if touch.state == MOVING and touch.deltaY < 0 then
    scene.camera.z = scene.camera.z - 0.04
    scene.camera.x = scene.camera.x - rotation / 816
    
    
    if voiceSpeech >= 0 and scene.camera.z <= -4 then
    voiceSpeech = voiceSpeech - 0.01
    music.volume = voiceSpeech
    end
end


    
if touch.state == MOVING and touch.deltaX > 0.3 then
    rotation = rotation - 1.5
    scene.camera.eulerAngles = vec3(0, rotation, 0)
    
    if rotation >= 90 then
        rotation = 0
    end
    
    if rotation <= -90 then
        rotation = 0
    end
 end
    
    


if touch.state == MOVING and touch.deltaX < 0.3 then
    rotation = rotation + 1.5
    scene.camera.eulerAngles = vec3(0, rotation, 0)
    
    
    if rotation >= 90 then
        rotation = 0
    end
    
    if rotation <= -90 then
        rotation = 0
    end
    end

    
if touch.tapCount == 2 and touch.state == BEGAN and BuildMode == true then 
    sound(asset.documents.Dropbox.bong_001)
    MakeBlock(vec3(scene.camera.x - rotation / 816, 0, scene.camera.z), vec3(0, rotation, 0)) 
end

if touch.state == BEGAN then
    
    body.linearVelocity = vec3(2, 0, 0)
    
end

if touch.state == BEGAN then
    if ROOM == false then
    if touch.x > 870 and touch.x < 1040 then
        if touch.y > 30 and touch.y < 230 then
            jumpOne = tween(0.5, scene.camera, {y = 1}, tween.easing.cubicOut)
            jumpTwo = tween(0.5, scene.camera, {y = 0}, tween.easing.cubicIn, function() sound(asset.downloaded.A_Hero_s_Quest.Drop) end)
            tween.sequence(jumpOne, jumpTwo)
            jumpPressed = true
                
            end
        end

end

    if touch.x > 960 and touch.x < 1060 then
        if touch.y > 700 and touch.y < 800 then
            if ROOM == false then
            ROOM = true
            if ROOM == true then
                scene.camera.position = vec3(-20, 1, -4)
                rotation = 0
                scene.camera.eulerAngles = vec3(-15, rotation, 0)
                tween(0.5, scene.camera, {y = 0, eulerAngles = vec3(0, rotation, 0)}, tween.easing.cubicIn, function() sound(asset.downloaded.A_Hero_s_Quest.Drop) end)
                CreateFloor(-20, -3.125, 0)
                CreateFloor(-20, -3.125, 4)
                CreateFloor(-20, -3.125, 8)
                CreateFloor(-20, -3.125, -4)
                CreateFloor(-20, -3.125, -8)
                CreateFloor(-24, -3.125, 0)
                CreateFloor(-24, -3.125, 4)
                CreateFloor(-24, -3.125, 8)
                CreateFloor(-24, -3.125, -4)
                CreateFloor(-24, -3.125, -8)
                CreateFloor(-20, 4.125, 0)
                CreateFloor(-20, 4.125, 4)
                CreateFloor(-20, 4.125, 8)
                CreateFloor(-20, 4.125, -4)
                CreateFloor(-20, 4.125, -8)
                CreateFloor(-24, 4.125, 0)
                CreateFloor(-24, 4.125, 4)
                CreateFloor(-24, 4.125, 8)
                CreateFloor(-24, 4.125, -4)
                CreateFloor(-24, 4.125, -8)
                CreateWalls(-20, 0.850, 9.5, vec3(0, 180, 0))
                CreateWalls(-24, 0.850, 9.5, vec3(0, 180, 0))
                CreateWalls(-25.5, 0.850, 8, vec3(0, 270, 0))
                CreateWalls(-25.5, 0.850, 4, vec3(0, 270, 0))
                CreateWalls(-25.5, 0.850, 0, vec3(0, 270, 0))
                CreateWalls(-25.5, 0.850, -4, vec3(0, 270, 0))
                CreateWalls(-25.5, 0.850, -8, vec3(0, 270, 0))
                CreateWalls(-18.5, 0.850, 8, vec3(0, 270, 0))
                CreateWalls(-18.5, 0.850, 4, vec3(0, 270, 0))
                CreateWalls(-18.5, 0.850, 0, vec3(0, 270, 0))
                CreateWalls(-18.5, 0.850, -4, vec3(0, 270, 0))
                CreateWalls(-18.5, 0.850, -8, vec3(0, 270, 0))
                CreateWalls(-20, 0.850, -9.5, vec3(0, 180, 0))
                CreateWalls(-24, 0.850, -9.5, vec3(0, 180, 0))
                MakeFurniture()
                sound(asset.documents.Dropbox["Success, win sound effect.wav"])
                pathOne = tween(0.5, tS, {x = 100, y = 50}, tween.easing.cubicInOut)
                delay = tween.delay(1.0)
                pathTwo = tween(0.5, tS, {x = 0, y = 0}, tween.easing.cubicInOut)
                tween.sequence(pathOne, delay, pathTwo)
               end 
            end
        end
        
        if touch.x > 960 and touch.x < 1060 then
            if touch.y > 700 and touch.y < 800 then
                housePressed = true
            end
        end
    
    if touch.x > 960 and touch.x < 1060 then
        if touch.y > 550 and touch.y < 650 then
            drawPressed = true 
            runOne = tween(1, scene.camera, {z = scene.camera.z + 10}, tween.easing.cubicInOut)
            swayOne = tween(0.25, scene.camera, {eulerAngles = vec3(0, rotation, 5)}, tween.easing.cubicInOut)
            swayTwo = tween(0.25, scene.camera, {eulerAngles = vec3(0, rotation, -5)}, tween.easing.cubicInOut)
            swayThree = tween(0.25, scene.camera, {eulerAngles = vec3(0, rotation, 0)}, tween.easing.cubicInOut)
            tween.sequence(swayOne, swayTwo, swayThree)
            
        end
        end 
        
        if touch.x > 960 and touch.x < 1060 then
            if touch.y > 400 and touch.y < 600 then
                
            end
        end
    end
    
    
        
   if touch.tapCount == 2 then
        if cameraSettings.fieldOfView == 45 then
            tween(0.5, cameraSettings, {fieldOfView = 15}, tween.easing.cubicInOut)
        end
        
        if cameraSettings.fieldOfView == 15 then
            tween(0.5, cameraSettings, {fieldOfView = 45}, tween.easing.cubicInOut)
        end
    end
        
    
    
   if touch.state == BEGAN then
        tpS.x = 0
        if tpS.x == 0 then
        tapOne = tween(1, tpS, {x = 3000}, tween.easing.cubicInOut)
        tapTwo = tween(1, alphaTapChannel, {x = 0}, tween.easing.cubicInOut)
        end    
    end

if touch.state == ENDED then
    
        
    
    if touch.x > 960 and touch.x < 1060 then
        if touch.y > 700 and touch.y < 800 then
            housePressed = false
        end
    end
    
    if touch.x > 960 and touch.x < 1060 then
        if touch.y > 550 and touch.y < 650 then
            drawPressed = false
        end
    end 
end
    


if touch.tapCount == 4 and ROOM == true then
    scene.camera.position = vec3(-20.2, 0, 7)
    scene.camera.eulerAngles = vec3(5, 180, 0)
end

if touch.tapCount == 5 and ROOM == true and scene.camera.position == vec3(-20.2, 0, 7) and scene.camera.eulerAngles == vec3(5, 180, 0) then
    scene.camera.eulerAngles = vec3(0, 0, 0)
    scene.camera.position = vec3(-20, 0, -4)
end

end
end

– Creates an image of an ellipse and rect

– Called automatically by codea
function draw()
update(DeltaTime)

-- Draw the scene
scene:draw()

-- Draw controls
sprite(asset.documents.Dropbox.shadedDark01, 950, 130, 200)
sprite(asset.documents.Dropbox.shadedDark21, 1010, 740, 100)
sprite(asset.documents.Dropbox.shadedDark48, 1010, 600, 100)
sprite(asset.documents.Dropbox.shadedDark34, 1010, 460, 100)

-- Draw crosshair
sprite(asset.documents.Dropbox.crosshair036, WIDTH/2, WIDTH/2 - 120, 50)

-- Make cool tapping effect
CreateTapEffect(CurrentTouch.x, CurrentTouch.y)




if ROOM == true then
    CreateRoomText()  
    makeLoadTransition()
end
end

Do you think you could edit my code and implement it in for me please??
Thank you :slight_smile:

Any asset you have in your Dropbox folder is an error for me because they’re not available to me.

What objects in your code are you trying to reposition to match another object.

I’m trying to reposition the blaster object so that every frame it’s position updates to be where the scene.camera is

I did a search for blaster and all I found was an empty function makeBlaster. I did a search for scene.camera and it’s all over the place. I’m not sure how much help I can give you because I can’t run the code and I don’t know what your program is supposed to be doing.

All the assets you have in Dropbox should be moved to the folder for that project. Tap on one of the assets to bring up the asset list and the project folder should be the top folder. Once all of you assets are in its project folder, you can zip the project and it will contain all of the assets you use. That zip file can be posted in the forum instead of the code and anyone would be able to load it and have everything they need to run it.

To move assets from the Dropbox folder, while in your code, tap a Dropbox asset to bring up the asset list. Get into Dropbox. Tap edit and select assets to move. Then tap add and it will ask you where you want to copy them. Select your project folder.