Colliders in unity behaving the way they, as I think, shouldn't - unity3d

I am learning to work with unity now and I noticed one error. I am working with 2D and have two box colliders.
One of them is:
Size : X = 8, Y = 0.3
Center: X = 0, Y = 4.9
The Other one is
Size : X = 3, Y = 0.6
Center: X = 0, Y = 3.95
So from this information we can see that the gap between those two colliders is 0.5, but a rigidbody with a circle collider with a radius of 0.25 is not able to move through that gap, it gets stuck.
Maybe there's something I don't know about the way colliders work and you could shed some light.

Related

Unable to rotate around the Z axis in RealityKit / ARKit

I'm creating an app using RealityKit and I'm having trouble rotating an element around the Z axis.
The element is an eyelid - which is essentially a sphere cut in half. My hope is to update the Z axis so it rotates. But no matter what I do, it does not move at all.
I am able to successfully rotate it around the x and y axis. But the z-axis seems to be stuck.
robot.topLidL?.orientation = simd_mul(
simd_quatf(angle: deg2rad(-80 + (130 * eyeBlinkLeft)), axis: [1, 0, 0]), // this line handles the blinking as expected
simd_quatf(angle: deg2rad((130 * browLeft) - (60 * browInnerUp)), axis: [0, 0, 1])) // this should rotate the eyelid around the z axis but it does not move at all.
I get 0 movement at all around the z-axis. I confirmed that I am getting values from browLeft and browInnerUp. I looked at the assets in Reality Composer and all looks well. An interesting note is if I change the Z value in Reality Composer, I do see the rotation in Composer as I would expect. But when I hardcode that value in my code, it still doesn't change rotation position.
I also just tried
robot.topLidL?.orientation = simd_quatf(angle: deg2rad((130 * browLeft) - (60 * browInnerUp)), axis: [0, 0, 1])
and that doesn't work either. I even just hardcoded:
robot.topLidL?.orientation = simd_quatf(angle: deg2rad(50), axis: [0, 0, 1])
And even that didn't cause any change.
Simply put, I'm getting no movement at all around the z-axis.
Do you have any ideas why this might be the case?
Additional code:
private func deg2rad(_ value: Float) -> Float {
value * .pi / 180
}

SceneKit's look(at:up:localFront:) not working right in certain scenarios

This can be reproduced using the default Xcode 3D game template (SpaceShip).
Remove the runAction line that rotates the ship in the GameViewController.
Add this line. The ship correctly faces away from the camera.
Note the very small x component in the at: parameter.
ship.look(at: SCNVector3(0.001, 0, -100.0), up: SCNVector3(0, 1, 0), localFront: SCNVector3(0, 0, 1)) // Works! Ship faces away from camera.
However, it the x component of the at: parameter is exactly zero, the ship's orientation does not change. The ship continues to face the camera instead of facing away from it.
ship.look(at: SCNVector3(0, 0, -100.0), up: SCNVector3(0, 1, 0), localFront: SCNVector3(0, 0, 1)) // DOES NOT work
Seeing the same problem with simdLook()
For starters, if you show the world origin sceneView.debugOptions = ARSCNDebugOptions.showWorldOrigin], you will see that the x and y axis are actually opposite to what they would normally be, i.e. x is now y and y is now x.
Second, you are changing the x axis and not z axis. If you want the spaceship to look away or at you, that runs along the z axis. Negative(-) z will look at you where Positive(+)z will look away from you. Trying just changing the -100 to +100.

How do i put my player on the Terrain ? The player is way down under the Terrain

The Main Camera the Player/s all down under the Terrain.
Before the Terrain i had a Plane but i deleted the Plane and added Terrain.
I changed the Terrain resolution to 2000 on 2000. And using the Terrain ToolKit.
When i'm running the game i see the player drop down under the Terrain.
The player scale and position are: Position: X = -1.7, Y = 2, Z = 1
And the player Scale: X = 1, Y = 1, Z = 1
The Terrain Position: X = 0, Y = 0, Z = 0
Terrain Scale: X = 0.9, Y = 0.9, Z = 2.5
What i want is when running the game that the player camera other players all will be on the Terrain or if it's the camera a bit above it like it was when the Plane was instead.
This is a screenshot example show where the Main Player is same the camera guards the light.
There are several ways to do it.
You can manually drag the players and camera above the terrain and setup their position as you need.
Otherwise you can set transform.position Vector3 above terrain transform.position Vector3 at Start() in the character controller script. If your camera have a following script in it, then it will be above the player as well as player. Else you have to do the same for camera.
Another way, you can manually drag the terrain under players and characters or set position under these at Start() of terrain.

Three.js camera rotation issue

I want to rotate the camera around the x-axis on the y-z plane while looking at the (0, 0, 0) point. It turns out the lookAt function behaves weird. When after rotating 180°, the geometry jump to another side unexpectedly. Could you please explain why this happens, and how to avoid it?
You can see the live demo on jsFiddle: http://jsfiddle.net/ysmood/dryEa/
class Stage
constructor: ->
window.requestAnimationFrame =
window.requestAnimationFrame or
window.webkitRequestAnimationFrame or
window.mozRequestAnimationFrame
#init_scene()
#make_meshes()
init_scene: ->
#scene = new THREE.Scene
# Renderer
width = window.innerWidth;
height = window.innerHeight;
#renderer = new THREE.WebGLRenderer({
canvas: document.querySelector('.scene')
})
#renderer.setSize(width, height)
# Camera
#camera = new THREE.PerspectiveCamera(
45, # fov
width / height, # aspect
1, # near
1000 # far
)
#scene.add(#camera)
make_meshes: ->
size = 20
num = 1
geo = new THREE.CylinderGeometry(0, size, size)
material = new THREE.MeshNormalMaterial()
mesh = new THREE.Mesh(geo, material)
mesh.rotation.z = Math.PI / 2
#scene.add(mesh)
draw: =>
angle = Date.now() * 0.001
radius = 100
#camera.position.set(
0,
radius * Math.cos(angle),
radius * Math.sin(angle)
)
#camera.lookAt(new THREE.Vector3())
#renderer.render(#scene, #camera)
requestAnimationFrame(#draw)
stage = new Stage
stage.draw()
You are rotating the camera around the X-axis in the Y-Z plane. When the camera passes over the "north" and "south" poles, it flips so as to stay right-side-up. The camera's up-vector is (0, 1, 0) by default.
Set the camera x-position to 100 so, and its behavior will appear correct to you. Add some axes to your demo for a frame of reference.
This is not a fault of the library. Have a look at the Camera.lookAt() source code.
If you want to set the camera orientation via its quaternion instead, you can do that.
three.js r.59

3d movement around a sphere

I'm working in 3d for the first time in a long time. Basically I'm rotating a sphere and projecting x y z cords to place things on the surface based on the spheres X and Y rotation.
Heres the code im using:
#define piover180 0.01745329252f
GLfloat cosy = cos(yrot * piover180);
island[i].x = rad * sin(xrot * piover180)* cosy;
island[i].y = rad * sin(yrot * piover180);
island[i].z = rad * cos(xrot * piover180) * cosy;
Problem is the Xrot positioning works fine but the Yrot placement always draw the objects into the north and south pole so they all cross at the top, which isn't correct for rotating. I need a way to solve this. Here's a picture to help explain:
Any help would be greatly appreciated, let me know if you need any more information?
The code sample you pasted is incomplete, because you didn't show how you applied these calculations via glRotate et al. Here's how I would do this. Although you could certainly optimize it by doing the matrix calculations yourself in one step, it's likely not necessary.
// Move object out to its radius
glTranslatef(radius, 0, 0);
// Apply latitudinal rotation (aka "Yrot")
glRotatef(latitude, 0, 1, 0);
// Apply longitudinal rotation (aka "Xrot")
glRotatef(longitude, 0, 0, 1);
After that, you can do the drawing. You'll also want to wrap the whole thing in calls to glPushMatrix and glPopMatrix to isolate this transformation.
I ended up solving it using the Spherical Coordinate System.
Here's the code:
island[i].x = rad*sin(xrot*(PI/180))*cos(yrot*(PI/180));
island[i].y = rad*sin(xrot*(PI/180))*sin(yrot*(PI/180));
island[i].z = cos(xrot*(PI/180));
Here are the equations:
x = r sinq cosf
y = r sinq sinf
z = r cosq
r = (x2 + y2 + z2)1/2
q = tan-1(z/(x2+y2)1/2)
f = tan-1(y/x)
Just in case anyone could do with it, it's perfect for camera control or any exact 3d coord calculations you need to do.
Reference: http://electron9.phys.utk.edu/vectors/3dcoordinates.htm