- Home /
Moving a camera (character) based on collision
I have 9 simple cubes. I also have a sphere with a rigidbody that collides with each of the cubes producing a "joystick effect". The sphere itself is controlled by a skeleton which is in turn controlled by Kinect.
Now I am programming the movement. If the sphere is on the "front" cube, the camera moves forward, continuously, for the duration of the time of the collision. I have this code so far. It doesn't work so far, and I'm not sure it is in the right direction.
The dirvar comes from the collision script, giving an integer from 1-8 to the var, indicating the cube hit. 1 is top, 2 is topright and so on.
var speed:float = 5.0;
var direction:Vector3 = Vector3.zero;
var character:CharacterController;
function Update()
{
character = this.GetComponent(CharacterController);
if (character.isGrounded)
{
switch(CollComp.dirVar)
{
case(1):
direction=Vector3(speed, 0, 0);
break;
}
character.transform.position.z+=speed*Time.deltaTime;
}
}
Answer by TomPendergrass · Jan 07, 2013 at 04:26 PM
direction = character.transform.right;
character.transform.position += direction speed Time.deltaTime;
Your answer
![](https://koobas.hobune.stream/wayback/20220613090537im_/https://answers.unity.com/themes/thub/images/avi.jpg)