Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by maki47 · Jan 25, 2016 at 03:39 PM · camera3dfightingame

Tekken Fighting game Camera

Hi, I'm working on this 3d fighting game, it's almost a tekken clone. Now I need to code the camera movement. I already have the code for the camera movement, it always lookAt the side of two characters. But my problem is I can't make it zoom Out/in as the player moves away from each other. I tried a lot of solution found in the internet but nothing solves it or related to it. Players move SSBB like in tekken, all scripts I found was for game whose characters are only moving on X-axis. Here's my code:

 using UnityEngine;
 using System.Collections;
 
 public class CameraMovement : MonoBehaviour {
     Transform player1;
     Transform player2;
     Transform mTransform;
     Transform mCenterTrans;
     public GameObject centerPoint;
     public Vector3 cameraOffset;
     public float height;
 
     float marginx = 3f;
 
     Vector3 center;
     Vector3 offset;
     void Start () {
         mCenterTrans = centerPoint.transform;
         mTransform = transform;
         player1 = Player.player1.mCharacter.mModel.transform;
         player2 = Player.player2.mCharacter.mModel.transform;
         centerPoint.transform.position = centerOfChars(player1.position,player2.position);
         offset = centerPoint.transform.position - transform.position;
     }
 
 
     void LateUpdate () {
         updatePosition ();
     }
 
     void updatePosition()
     {
         //calculate distance of players
         float distanceOfCharacters = Vector3.Distance (player1.position, player2.position);
 
         //update centerPoint position
         mCenterTrans.position = centerOfChars(player1.position,player2.position);
         mCenterTrans.LookAt (player2.position);
 
         //calculate for nexPosition of Camera
         float angle = (mCenterTrans.eulerAngles.y);
         float anglez = (mCenterTrans.eulerAngles.z);
         Quaternion rotation = Quaternion.Euler (0, angle,0);
         mTransform.position = mCenterTrans.position - (rotation * offset);
         center = mCenterTrans.position;
 
         //add height to camera
         center.y += height;
         mTransform.LookAt (center);
     }
 
     Vector3 centerOfChars(Vector3 pCharPos1,Vector3 pCharPos2)
     {
         return (player1.position + player2.position) * 0.5f;
     }
 }
 

Any help if you can?

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

3 Replies

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

Answer by maki47 · Jan 25, 2016 at 04:11 PM

For FUTURE READERS I got it! Just use the distance from the center to the location of one of the objects, and multiplied it. Use some margin and limit its zooming

 Vector3 cameraNewPos = mCenterTrans.position - (rotation * offset * (distanceOfCharacters/2f) * margin);
         cameraNewPos.x = Mathf.Clamp (cameraNewPos.x, minZoom, maxZoom);
         mTransform.position = cameraNewPos;

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 thomas1231 · May 14, 2017 at 01:35 AM

Just wanted to ask did you make a controller that work like Tekken and if so how

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 miworldtube · Jul 18, 2018 at 02:14 AM

Hi, thank you so much. can we see a demo ?

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

49 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to hide and show level based on player/camera position? 0 Answers

Character quickly vibrates when reaching specific objects. 0 Answers

Camera Shaking At High Speed 0 Answers

How do I make my camera Switch between 2 layer views? 0 Answers

Can i do an app in "2D" that changes in VR mode when i want? 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