#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# I’m trying to get rotation to work

edited November 2018 Posts: 18

I’ve got a Codea scene in craft where I am tweening a couple of spheres going around a path, but I would like to do some rotations, but no matter what I put into the tweening code the spheres do not rotate at all.

Here’s a sample of my tweening code.

t1 = tween(1.0, myEntity1, {scale (.5,.5,.5), x = -1, y = -.25, z = 6,}, tween.easing.linear)
t2 = tween(.1, myEntity1, {rotate (30,0,0,1), scale = vec3(.8,.4,.25), x = -1, y = -.5, z= 6}, tween.easing.linear)
t3 = tween(1.0, myEntity1, {scale = vec3(.3,.8,.3), x = -1, y = 3, z = 10}, tween.easing.linear)
t4 = tween(1.0, myEntity1, {scale = vec3(.5,.5,.5), x = 1, y = 3, z = 10}, tween.easing.linear)
t5 = tween(1.0, myEntity1, {x = 1, y = 1, z = 3}, tween.easing.linear)
t6 = tween(1.0, myEntity1, {x = -1, y = 1, z = 3}, tween.easing.linear)

Tagged:

• Mod
Posts: 9,249

@Kurall_Creator Here’s an example of a cube. The tweens change the cube position and rotation.

``````function setup()
assert(craft, "Please include Craft as a dependency")
scene = craft.scene()
scene.camera.position=vec3(0,0,-10)

c = scene:entity()
c.model = craft.model.cube(vec3(1,1,1))
c.material = craft.material("Materials:Specular")
c.material.map = readImage("Surfaces:Desert Cliff Roughness")

rot = {x=0,y=0,z=0}
tween(4,rot, {x=360,y=720,z=1080},
{easing = tween.easing.linear,loop = tween.loop.pingpong})

pos = {x=0,y=-10,z=20}
tween(6,pos, {x=0,y=1,z=-9},
{easing = tween.easing.linear,loop = tween.loop.pingpong})
end

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

function draw()
update(DeltaTime)
c.rotation=quat.eulerAngles(rot.x,rot.y,rot.z)
c.position=vec3(pos.x,pos.y,pos.z)
scene:draw()
end
``````
• edited November 2018 Posts: 18

Thank you so much.

I’m envisioning an animation where a couple of primitives will start attacking each other, and I’ve got rotations working perfectly within my original tween sequence.

Thank you so much for your help!

t7 = tween(1.0, myEntity2, {scale = vec3(.5, .5, .5), x = 0, y = -.25, z = 3}, tween.easing.linear)
t8 = tween(4,rot, {x=360,y=720,z=1080}, tween.easing.linear)
t9 = tween(.1, myEntity2, {scale = vec3 (.8, .4, .25), x = 0, y = -.5, z = 3}, tween.easing.linear)
t10 = tween(1.0, myEntity2, {scale = vec3 (.3, .8, .3), x = -1, y = 1, z = 3}, tween.easing.linear)
t11 = tween(1.0, myEntity2, {scale = vec3 (.5,.5,.5), x = -1, y = 3, z = 10}, tween.easing.linear)
t12 = tween(1.0, myEntity2, {x = 1, y = 3, z = 10}, tween.easing.linear)
t13 = tween(1.0, myEntity2, {x = 1, y = 1, z = 3}, tween.easing.linear)

``````tween.sequence(t7, t8, t9, t10, t11, t12, t13)
``````