Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ODPaterson · Nov 23, 2010 at 08:00 PM · camerachangeflip

Can I make the camera flip upside-down when spacebar is pressed?

I making a game which involves flipping gravity so that the player travels on the ceiling when space is pressed.

The problem is that when gravity is switched round the camera doesn't switch round too which makes things very disorienting!

Thanks in advance to anyone who can help out!

[Edit]

More detail:

The camera is attached to a vehicle with this script:

using UnityEngine;

using System.Collections;

public class CarCamera : MonoBehaviour { public Transform target = null; public float height = 1f; public float positionDamping = 3f; public float velocityDamping = 3f; public float distance = 4f; public LayerMask ignoreLayers = -1;

private RaycastHit hit = new RaycastHit();

private Vector3 prevVelocity = Vector3.zero; private LayerMask raycastLayers = -1;

private Vector3 currentVelocity = Vector3.zero;

void Start() { raycastLayers = ~ignoreLayers; }

void FixedUpdate() { currentVelocity = Vector3.Lerp(prevVelocity, target.root.rigidbody.velocity, velocityDamping * Time.deltaTime); currentVelocity.y = 0; prevVelocity = currentVelocity; }

void LateUpdate() { float speedFactor = Mathf.Clamp01(target.root.rigidbody.velocity.magnitude / 70.0f); camera.fieldOfView = Mathf.Lerp(50, 70, speedFactor); float currentDistance = Mathf.Lerp(4f, 2.25f, speedFactor);

 currentVelocity = currentVelocity.normalized;

 Vector3 newTargetPosition = target.position + Vector3.up * height;
 Vector3 newPosition = newTargetPosition - (currentVelocity * currentDistance);
 newPosition.y = newTargetPosition.y;

 Vector3 targetDirection = newPosition - newTargetPosition;
 if(Physics.Raycast(newTargetPosition, targetDirection, out hit, currentDistance, raycastLayers))
     newPosition = hit.point;

 transform.position = newPosition;
 transform.LookAt(newTargetPosition);


}

}

I've tried to make a flipping script like this:

function Update() { if (Input.GetKeyDown(KeyCode.Space)) { ; transform.Rotate(0, 0*Time.deltaTime, 180); } }

This camera flipping script works but not with the camera with a vehicle script attached at the same time.

My guess is something in a that big script is messing up my little script...

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jesse Anders · Nov 23, 2010 at 08:24 PM 0
Share

Not enough info - you haven't said how the camera is controlled, or even whether the game is 1st-person or 3rd-person. If you still need help with this, edit your post to include more info (and perhaps your camera control code as well).

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ODPaterson · Dec 07, 2010 at 01:21 PM

Sorted.

I attached a camera movement script to a cube, removed its mesh renderer and then made the main camera a child of it. I then added this script:

function LateUpdate() {
if (Input.GetKeyDown(KeyCode.Space)) {
     transform.Rotate(0, 0*Time.deltaTime, 180);
}

}

to the main camera.

This means the camera movement script and the camera flip script don't interfere with each other.

There was almost certainly a better and more elegant way of solving this problem, but I'm not a programmer, I'm pushed for time and this works so it's all good :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Siim · Nov 23, 2010 at 08:24 PM

You need to rotate the camera by 180 degrees

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ODPaterson · Nov 23, 2010 at 10:13 PM 0
Share

The problem I have is that I need a script which does this and I'm useless at scripting so I don't know where to start :S

avatar image
0

Answer by azzogat · Nov 28, 2010 at 09:53 AM

On an empty object, this should do the trick:

    if (Input.GetButtonUp ("Jump")){
transform.eulerAngles = Vector3(0, 0, 180); 
}

If you're planning on getting anywhere with your project, I recommend you take the time to understand any external snippet of code you're using. The Scripting Reference is your friend :

http://unity3d.com/support/documentation/ScriptReference/Transform-eulerAngles.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ODPaterson · Nov 30, 2010 at 07:35 PM 0
Share

Thanks, but it doesn't seem to work :S. I have a camera flip script but it just gets overwritten by the camera follow script. When I press space the camera view flickers to the right position for a millisecond but ultimately stays the same. If I could wok out what was doing that I'd be alright I think.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Flip/Mirror > Camera? 6 Answers

Why does my fly though camera flip over on the first call of Input.GetAxis("Mouse X") (or Y)? 1 Answer

Player follow object changes direction when the player does 0 Answers

Mirror flip camera? 4 Answers

How to rotate the camera on a button press. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges