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 shucke · Apr 04, 2011 at 04:50 PM · cameramovementheight

Camera Height (y)

im working on a space shooter and bumped into a little problem... im using a script to control my camera movement but it always stays at the same height. i don't know how to add height to this script. i hope someone can help me with this problem.

here's the script im using:

var target : Transform; var distanceToFollow : float = 5.0; var height : float = 1.0; var moveSpeed : float = 1.0; var rotationSpeed : float = 0.2; var damping = 6.0; var smooth = true;

private var targetRay : Ray; @script AddComponentMenu("Camera-Control/Smooth Look At")

function Update () {

 targetRay = new Ray(target.position,-target.forward);
 point = targetRay.GetPoint(distanceToFollow);
 point = Vector3.Slerp(transform.position, point, Time.deltaTime * moveSpeed);
 transform.position = point;

 transform.LookAt(target,target.up);


} function LateUpdate () { if (target) { if (smooth) { // Look at and dampen the rotation var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); } else { // Just lookat transform.LookAt(target); } } } function Start () { // Make the rigid body not change rotation if (rigidbody) rigidbody.freezeRotation = true; }

'

Comment
Add comment
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

2 Replies

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

Answer by Henri 1 · Apr 05, 2011 at 08:04 AM

Or, you can use the Spring Follow camera, and set the applicable height and distance

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 Owen-Reynolds · Apr 05, 2011 at 03:53 PM 0
Share

That's the one where it sets desired camera position, desired look position and smooths them in? I've found that general idea to be the most versitile.

avatar image
0

Answer by Owen-Reynolds · Apr 05, 2011 at 12:50 AM

Think about specifically where you want your camera to be and which way it should be looking.

These script comments may or may not be helpful:

// shoot a ray from the player (target.position) straight backwards
// (-target.forward is the same as target.backward):
targetRay = new Ray(target.position,-target.forward);
// set the camera position to be 5 away on that line:
point = targetRay.GetPoint(distanceToFollow);

If you adjust where you shoot from, then the camera will be somewhere else. For example, using target.position + target.right*3 will start the ray 3 to the player's right.

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

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

Want to apply "height" to my DeadSpace Camera --> Physics.Linecast gives me trouble 1 Answer

How to use Android Accelerometer(Left and right tilt) to turn a sphere object and camera in that direction? 1 Answer

Moving forward in 3D 1 Answer

Why is an object's movement jerky, when the camera is also moving by following a different rigidbody? 3 Answers

Move a Game Object (Camera) forward and sideways with the Mobile Sensor Outputs. How? 0 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