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 Ravart · Mar 09, 2011 at 02:44 PM · cameramovementheightlinecastlook

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

Ok, I have a script that simulates a DeadSpace Third Person Camera. The script gets applied to the camera and the "target" is the player.

The script works fine, till i tried to apply "height". Some characters are bigger, some are smaller, therefore applying a value height makes sense. Sadly Physics.Linecast gives me strange results. I tried many things, but i can't find the error.

It seems like Physics.Linecast use the orgin model high, while camera and controls using the new height (origin height + variable height). Can someone help me out of this mess? Thx!

using UnityEngine; using System.Collections;

public class Camera_DeadSpace : MonoBehaviour {

public Transform target;

public float distance = 2.0f; public float height = 0.8f;

public float in_damping = 6.0f; public float out_damping = 3.0f;

public float sensitivityX = 150F; public float sensitivityY = 150F; public float minimumY = -60F; public float maximumY = 60F;

public float minDistance = 0.0f; public float maxDistance = 4.0f; public float smooth = 10.0f;

private bool showCrosshair = false; private GUISkin skin = null; private float rotationY = 0F; private float rotationX = 0F; private float currentDistance;

void Awake(){ currentDistance = distance; }

// Update is called once per frame void LateUpdate () { Screen.showCursor = false; Screen.lockCursor = true;

 Vector3 position = target.position;

//HERE IS THE PROBLEM !!! IF YOU USE THIS LINE IT KILLS THE SCRIPT!!! //position.y = height + target.position.y;

 Vector3 transpos, targetrot;
 Quaternion transrot;


 if (!Input.GetButton("Aim")){
     showCrosshair=true;
     float wantedDistance = distance;

     currentDistance = Mathf.Lerp (currentDistance, wantedDistance, out_damping * Time.deltaTime);

     rotationX += Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
     rotationY -= Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;
     rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);


     transrot = Quaternion.Euler(rotationY, rotationX, 0) ;
     transpos = (Quaternion.Euler(rotationY, rotationX, 0)) * new Vector3(0.0f, 0.0f, -currentDistance) + position;

     targetrot = new Vector3(0, rotationX, 0);
 }
 else{
     showCrosshair=true;
     float wantedDistance = 0;

     currentDistance = Mathf.Lerp (currentDistance, wantedDistance, in_damping * Time.deltaTime);

     rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
     rotationY -= Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;
     rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

     transrot = Quaternion.Euler(rotationY, rotationX, 0) ;
     transpos = (Quaternion.Euler(rotationY, rotationX, 0))  * new Vector3(0.0f, 0.0f, -currentDistance) + position;

     targetrot = new Vector3(0, rotationX, 0);
 }

 Vector3 desiredCameraPos = transpos;

 RaycastHit hit;
 //float distance2 = 0;

 if( Physics.Linecast( position, desiredCameraPos, out hit ) ){
     print("hit " + hit.distance);
     transpos = (Quaternion.Euler(rotationY, rotationX, 0))  * new Vector3(0.0f, 0.0f, -hit.distance)  + position;
 }

 transform.rotation = transrot;
 transform.position = transpos;
 target.localEulerAngles = targetrot;

}

// Use this for initialization void Start () {

} }

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 MiraiTunga · May 02, 2012 at 12:58 PM 0
Share

i just tried to use the same script you are using,and had the same problem ,i am relatively new to program$$anonymous$$g and usually use java , how do u add a $$anonymous$$imum to hit.distance?

Thanks---not sure about the rules of posting here hope iam in the right place

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ravart · Mar 10, 2011 at 10:55 AM

I didn't find a solution, but a workaround! Add to hit.distance a minimum distance like 0.2f

Cheers

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

1 Person is following this question.

avatar image

Related Questions

Camera Height (y) 2 Answers

Camera Stutter During Distance Correction 0 Answers

How to rotate a Rigidbody without rotating the gameObject? 1 Answer

How to resize camera view port without changing what is on screen 1 Answer

Moving forward in 3D 1 Answer


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