playMaker

Author Topic: Controllable camera with movement around multiple axes  (Read 4073 times)

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Controllable camera with movement around multiple axes
« on: November 18, 2013, 07:50:13 AM »
I've had no luck with this question elsewhere so I thought I'd give it a go here. You lot are a helpful bunch after all :)

My game is 3d and set in a cylindrical tunnel, the player must rotate around this tunnel in order to perform platforming puzzles. The tunnel endlessly generates and moves past the player at speed while they stay fixed at 0, 0, 0 (think of something like Outrun or Super Hang-On, where the track moves to give the illusion of forward motion).

What I would like is for the camera to freely rotate around the Z-axis with an offset from the centre of the tunnel, while also being able to move 'up' and 'down' in it's local Y-axis for jumps and vertical movement within the game-world (using gravity if possible). Something like this...



As well as this the camera needs to collide with various objects inside the tunnel such as ramps, raised platforms, obstacles, as well as the tunnel itself. If the player falls outside the tunnel they 'fail' and have to restart.

My current setup has a gameobject with a sphere collider and rigidbody attached, with the camera attached as a child. I have the y-axis movement (jumps) handled by an add force action in PM, they all seem to work ok.

The difficulty comes in rotating this gameobject. The rotation needs to be fixed from 0,0,0 otherwise the player will exit the tunnel. I can't seem to get the rotation working correctly at all. I'm at a loss as to what to try next with it tbh. I think maybe a configurable joint might help?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14957
  • Official Playmaker Support
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #1 on: November 18, 2013, 11:15:21 PM »
Hi,

 you need to create a camera platform with a careful hiearachy placement and it will work just fine!


1: Have an empty gameobject called "Camera Platform" that is located at the center of your screen.
2: Attach the camera to that platform.
3: For any rotation movement, control the "Camera Platform",
4: For any jumps, control the camera itself.



 Does that make sense?

bye,

 Jean

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #2 on: November 19, 2013, 04:31:22 AM »
Hi Jean, thanks for posting.

I have a "Camera Platform" at 0, 0, 0 with the camera attached as a child to it like you say. I'm using add torque to rotate the platform and add force (impulse) to make the camera jump.

It sort of works! (hurray) However the camera rotates around its own centre point rather than that of its parents. I feel like this could possibly be due to constraints on the rigidbody component of the camera perhaps?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14957
  • Official Playmaker Support
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #3 on: November 19, 2013, 05:45:40 AM »
Hi,

 You can't mix gameobject hierarchies and Physics, the hierarchy will be completly ignored. Use Physics joints then.

Also, in your case, I would no use physics at all for the camera, why would you need it?

bye,

 Jean

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #4 on: November 19, 2013, 05:52:40 AM »
The camera needs to collide with the tunnel, obstacles in it and react to gravity.

I think I may need to use a kind of plane joint on the camera to get it to work in that case. This is where I have been having problems in the past. I can't seem to figure out the right boxes to tick on the configurable joint to get it all behaving nicely.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14957
  • Official Playmaker Support
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #5 on: November 19, 2013, 05:55:30 AM »
Hi,

 Confusing, because you said the tunnel is rotating not the player... so the gravity won't affect the camera at all. Unless I misunderstand your setup.

 if your camera is affected by gravity, then you don't need any of the setup I mentionned of course. and actually you should rely on the physics to provide your rotation and simply add a force on the sides of the camery to achieve rotation. OR at least affect your player with a force using the axis taken from the camera transform itself.

 Bye,

 Jean

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #6 on: November 19, 2013, 06:03:38 AM »
Ahh, I apologise if that wasn't clear. I do want to rotate the player, not the tunnel. I would like the player camera to be 'stuck' to the sides of the tunnel with gravity, with its y-axis always pointing towards 0, 0, 0.

Ok that's interesting. I hadn't thought about doing it that way, I had always considered rotating the camera around a point to be the best approach. I'll give this a go and see what happens.

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #7 on: November 19, 2013, 08:45:26 AM »
Right so this pretty much works, thanks a lot Jean :)

The only issue I have now is making sure the camera's y-axis (up) always points towards the centre of the tunnel (0,0,0). I have tried using a look at action which sort of gives the right results, but instead of rotating the y-axis it uses the camera's 'forward' axis which is z.

I think maybe I could do this with some math, but I'd prefer not to if possible! :p

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14957
  • Official Playmaker Support
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #8 on: November 19, 2013, 09:33:25 AM »
Hi,

 Look at always takes two directions, the look at direction and the "up" direction, so you need to tweak both to achieve the right look up behavior in your case.

bye,

 Jean

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #9 on: November 19, 2013, 10:31:06 AM »
Thanks so much Jean, I think I have this working now.

I do have one more question though! Since you mentioned about rotating the tunnel rather than the player it got me thinking about why I decided to do it the other way as it was originally my intention to only move the tunnel.

I concluded that I didn't really have a good reason for moving the player. I'm not sure why I went down this route! So I just quickly set it up so the tunnel rotates to see if that would help to jog my memory and one thing has popped up.

When the player collides with an object in the tunnel on the players x-axis they end up going straight through the object. Now I think this is to do with the constraint I have on the player's x-axis position. The problem is if I don't constrain the player in the x-axis the collider ends up shifting from its fixed location making things go a bit wonky.

Ideally the player would collide with the object and just stop. Do you have any idea of how I could achieve this?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14957
  • Official Playmaker Support
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #10 on: November 19, 2013, 10:18:19 PM »
Hi,

 you may have gone too far with your physics setup, you need to bring it back to a minimum and it should work a lot better.

 How is your tunnel collider mesh made of? a tunnel is concave, you may have problems with this actually. Can you tell us more about how you generated that tunnel and its collider?

bye,

 Jean

MattBradley

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #11 on: November 20, 2013, 03:31:24 AM »
Right now I just have 'generate colliders' ticked on the mesh import and that seems to be doing an ok job of having the player collide with the tunnel surface when the tunnel is set to kinematic. Though when I untick it the player no longer collides with the mesh so that could be a problem.

What's best practice for stuff like this? Compound colliders?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14957
  • Official Playmaker Support
    • View Profile
Re: Controllable camera with movement around multiple axes
« Reply #12 on: November 20, 2013, 09:11:50 PM »
Hi,

 I would generally totally avoid concave mesh colliders, but in your case.... I guess you have no choice...

bye,

 Jean