Rotate the world

Hi all.
Im working on a 2.5D side scroller and need the world to rotate 180 dgrees at giving point in time.
i know that one can do a transform.rotate on a single object but my issue is that the whole level is made up of alot of objects.

So can i do the transform.rotate on the main camera or do i need to group all the level objects into on and then transform.rotate?

you mad? that will make your FPS go down
first of all, every attached object’s (attached to your world) Vector3 positions will be changed and recalculated every frame on and on and on.
secondly whenever you will shoot a bullet other than raycast (which is instant), your bullet will change trajectory, because the whole world has changed it’s transform

and thirdly… attach your main camera to an empty game object as a child. Place game object where you want camera to look at. Let’s say Vector3(0,0,0) or Vector3.zero in short. Use script to rotate empty game object and Mathf.Clamp the values. So where ever empty game object will rotate, camera child will follow it without need to translate or rotate it yourself with heavy math.
Next for cutscenes add some gizmos or other empty game objects and make camera to.LookAt them, still keeping it’s distance, transform and rotation from parent object

ok.
Heres is how it works at the moment.

My main cam follows the Player object via a follow script.

So if i understand you correctly i need to make the player object rotate and not the world?

Ahh, no, that is totally different story. Can you please provide some example game title, i’ll look up for it in youtube. Sorry i don’t really have an idea on what are you trying to achieve then. But yeah, main idea is not to rotate world, but rotate camera, and to simplify things, rotate empty object as camera’s parent, that will be easier than doing math. You don’t need to rotate player, you can have that empty gameObject attached as child to your player and have camera to be a child of game object. So gameObject is a parent for camera, but child of player… and player is a parent to both of them. That should give you more freedom

player
	- gameObject
		- camera

But yeah, an example wouldn’t hurt

Ok i think i follow :slight_smile:

Here is one
And yet it moves.

Its the same effect im looking for except i only need the “world” to rotate 180 when the character activates a switch.

Ha! That is achieved very simple.
First of all say bye bye to Transform.translate and such. You will be working with rigid body, it’s velocity and FixedUpdate()
Second search for Faux Gravity script on forum. There are i believe 3 awesome scripts. I used original author’s and it works.

And again, try avoiding math as much as possible (as in less calculations i mean, if you can trick it)

Now for this to work, you must remember, that you cannot change Unity’s built-in gravity. However you can switch it off and use your own! That is what Faux Gravity script does.
You will be working only with Global Axis (Space.World) for movement and rotation of your character. Yes you will be rotating character. Why global axis? Because, you will be using player’s local axis (Space.Self) to constantly keep negative Y velocity. That velocity will keep pushing player down, simulating gravity, no matter how he rotates in global axis. Yes less math again, woot!

Here’s an image on how you need to do it:

Your Hero (player) will be a parent for your camera. That is all! As player rotates in Global Space, so will camera. But player’s Local negative Y axis will keep pushing player “down” acording to it’s rotation in Global environment. Camera simply follows along, no scripting, math or rotating the world.

EDIT: Faux gravity (fake gravity - blue ring) is a child object of player too, but not camera. Both Camera and Fux Gravity empty game object are equal children of Player parent. As player rotates, so does camera and gravity.

COOOOOOL!!! Thanks :slight_smile:
Ill give this a try. :slight_smile:

hmmm turns out that this isent the way to go for me :frowning:

I my case im not interested in F’ing around with gravity , what i need to do is to rotate the platforms in the level 180 degrees when the hero flips a switch or collides with a trap.

Found this vid

and thats the effect i want.

my maine issue is that the level it build with many many different objects and how do i groupe these objects together so the level groupe has a centered ancher point and dosent rotate ascrew

use empty game objects as parents to make groups then
don’t know why you did not like my idea, but:

  1. you will have to learn and do alot more scripting
  2. use math and geometrical equations.

there is no Fking around with gravity, it’s more like - improving it. All there is - making extra object, that will act as gravity by pulling objects to it. Simple. There are probably consequences, but it’s a huge knowledge-time trade off

Have you trying simply parenting everything to an object and rotating that object? Using the RotateAround function would do great there.

i do like the idea of Faux gravity :slight_smile:
im just not sure that is the thing to use in my game. I dont need the hero to stick to the “roof” of the platform but rather the platform to change angle.

Maby im missing something i the Faux script i found?!

http://forum.unity3d.com/threads/8873-Faux-Gravity-making-my-brain-spin…-Help!?highlight=Faux+Gravity+script

And im also using the character controller and not rigid body on the player object

What is the best way to go about that? Create an empty and nest all the platforms in there or parent them to a cube object and disable the mesh renderer ?

You can absolutely alter or turn off Unity’s gravity. See the documentation here. The easiest way to do what I think you’re trying to do is to rotate the camera, and when you do, set the gravity like so
Physics.gravity = -cameraTransform.up; For reference, to “turn off” gravity, you’d simply set Physics.gravity = Vector3.zero

woah, did not know that one, that makes it even more interesting. That makes it even easier.
However if you wanted to use multiple gravities for different game objects or jumping between them (Mario style), this wouldn’t work, so faux script comes in handy in that case

Edit: made a quick glance at reference, yeah you can also switch it off with Rigidbody.useGravity = false;

Cheers burnumd

-Ray

Thanks burnumd that looks like it would do the trick :slight_smile:
Gonna test it tomorrow

I thought I might have had something for you, but after watching your video maybe not. Either way I had a similar style project started a while back, but it took a move to the back burner… it was a 2d / 3d game. A 2d side scroller with a 3d map / environment… kind of a side scroller that didn’t just go left to right. Here’s a link to the web player (it was just a test of weapons and world rotation using the 2d starter kit)

2D / 3D Gun web player

It has decent working guns and a bow and arrow style 2d weapon

Basic Controls:

arrows - movement
space - jump
left mouse - fire
1 - machine gun
2 - 3 shot burst
3 - shot gun
4 - Arrow
5 - Rocket
run to an intersection… if a white arrow appears you can press the up or down arrow keys to rotate the world to take the path

As I said before, this wasn’t fully functioning before I set it aside so there are problems, but you can see level rotation in and working

The video: And Yet It Moves Wii - Dying - IGN

The world (all objects that are not the player are parented to a single object) turns on a pivot. You would freeze physics, then turn the world around the player (transform.RotateAround()…) Then resume physics and let it fly.

The Youtube video has so little World pivoting that it is hard to say that you should treat it the same, however, the parts that do, I would do the same thing. What I do see more of is a very cool camera effect that pushes the camera out further the faster you go.

Novashot. Your demo looks like a decent start, however, the total effect does not work so well because in your case, you literally just need ot rotate the camera. When you do your rotation then, none of the physics blocks move around. I also saw alot of shifting on the platform which was a little disconcerting. I think you were overthinking the concept of the game.

BINGO!! This is the way to go… Thanks :slight_smile:

Now im just stock in the script.

How do i get it to turn 180 on key down?
with a Loop or?

Now it turns until i release the key

var TheTarget : Transform;
function Update () {
	    
var directionVector = new Vector3(0, 0, transform.position.z);

    if (Input.GetKey (KeyCode.UpArrow)) {
      
       transform.RotateAround (TheTarget.transform.position, directionVector, 180 * Time.deltaTime);
    }
    
     if (Input.GetKey (KeyCode.DownArrow)) {
      
       transform.RotateAround (TheTarget.transform.position, directionVector, -180 * Time.deltaTime);
    }   
    
    
}

As in the game, you would add in some timing stuff…

var timeScale=1.0;

if (Input.GetKey (KeyCode.UpArrow)) {
timeScale=0.0;
transform.RotateAround (TheTarget.transform.position, Vector3.up, 180 * Time.deltaTime);
}

Time.timeScale=timeScale;

hmmm this time code makes the game engine stall :slight_smile: