So… two problems I have with my game. In it, the player is a circle that moves around another big circle. I’m trying to make the player jump but it’s not working, and the collision detection isn’t working how it should. Is there anyway for someone to fix and revamp my code??
-- Odd
assert(OrbitViewer)
function setup()
-- Create a new craft scene
scene = craft.scene()
scene.physics.gravity = vec3(0, -14, 0)
scene.sky.material.sky = color(255, 72, 0)
scene.sky.material.horizon = color(224, 147, 143)
cameraSettings = scene.camera:get(craft.camera)
cameraSettings.nearPlane = 0.001
viewer.mode = FULLSCREEN
rotation = 0.15
rotation2 = 0
-- Create a new entity
earth = scene:entity()
earth.model = craft.model(asset.builtin.Primitives.Sphere)
earth.position = vec3(0, 0, 0)
earth.eulerAngles = vec3(0, 0, 0)
earth.scale = vec3(1, 1, 1) / 8
earth.material = craft.material(asset.builtin.Materials.Standard)
earth.material.diffuse = color(186, 255, 0)
player = scene:entity()
body = player:add(craft.rigidbody, STATIC)
player.model = craft.model(asset.builtin.Primitives.Sphere)
player:add(craft.shape.model, player.model)
player.position = vec3(0, 0, -0.4)
player.eulerAngles = vec3(0, 0, 0)
player.scale = vec3(0.1, 0.1, 0.1) / 8
makeSpike(vec3(0, player.y, -0.13), quat.eulerAngles(-90, 90, -90))
scene.camera.z = -0.5
end
function makeSpike(p, e)
spike = scene:entity()
sb = spike:add(craft.rigidbody, STATIC)
spike.model = craft.model(asset.builtin.CastleKit.towerTopRoof_obj)
spike:add(craft.shape.model, spike.model)
spike.position = p
spike.rotation = e
spike.scale = vec3(0.01, 0.01, 0.01) / 8
end
function touched(touch)
if touch.state == BEGAN and touch.tapCount == 2 then
zoomOne = tween(0.25, cameraSettings, {fieldOfView = 35}, tween.easing.cubicIn)
zoomTwo = tween(0.25, cameraSettings, {fieldOfView = 45}, tween.easing.cubicOut)
tween.sequence(zoomOne, zoomTwo)
end
if touch.state == MOVING and touch.deltaX > 0 then
rotation = rotation + 2
end
if touch.state == MOVING and touch.deltaX < 0 then
rotation = rotation - 2
end
if touch.state == MOVING and touch.deltaY > 0 then
rotation2 = rotation2 + 2
end
if touch.state == MOVING and touch.deltaY < 0 then
rotation2 = rotation2 - 2
end
end
function update(dt)
-- Update the scene (physics, transforms etc)
scene:update(dt)
player.rotation = quat.eulerAngles(rotation2, rotation, 0)
player.position = player.forward * 0.068 * 2.0
end
-- Called automatically by codea
function draw()
update(DeltaTime)
-- Draw the scene
scene:draw()
end
function calc()
x = math.abs(player.x - spike.x)
y = math.abs(player.y - spike.y)
z = math.abs(player.z - spike.z)
if x<2 and y<2 and z<2 then
end
end
Thanks in advance