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
2
Question by christianrod97 · Dec 17, 2016 at 11:53 PM · 3dmultiplayercamera followofflinefighting

3D Arena Fighter Camera (Local Multiplayer)

Hi There.

I've been stuck on this problem for awhile. I am trying to recreate the camera seen in Power Stone 2 (For reference https://youtu.be/EEiPj30yKMk?t=12m27s). Essentially, it is a multiplayer arena brawler in 3D. Think Smash Bros. with a Z-axis included. My current script can so far take one player and do a smooth follow, but it can't take other players.

 using UnityEngine;
 using System.Collections;
 
 public class SmoothFollow : MonoBehaviour
 {
     #region Consts
     private const float SMOOTH_TIME = 0.3f;
     #endregion
 
     #region Public Properties
     public bool LockX;
     public float offSetZ;
     public bool LockY;
     public bool LockZ;
     public bool useSmoothing;
 
     public Transform target;
 
     public GameObject hudElements;
     #endregion
 
     #region Private Properties
     private Transform thisTransform;
     private Vector3 velocity;
     #endregion
 
     bool hudActive = true;
 
 
 
     private void Awake()
     {
         thisTransform = transform;
         velocity = new Vector3(0.5f, 0.5f, 0.5f);
     }
 
     void Update()
     {
         if (hudActive)
         {
             if (Input.GetKeyDown(KeyCode.H))
             {
                 hudElements.SetActive(false);
                 hudActive = false;
             }
 
         }
         else
         {
             if (Input.GetKeyDown(KeyCode.H))
             {
                 hudElements.SetActive(true);
                 hudActive = true;
             }
         }
     }
 
     // ReSharper disable UnusedMember.Local
     private void LateUpdate()
     // ReSharper restore UnusedMember.Local
     {
         var newPos = Vector3.zero;
 
         if (useSmoothing)
         {
             newPos.x = Mathf.SmoothDamp(thisTransform.position.x, target.position.x, ref velocity.x, SMOOTH_TIME);
             newPos.y = Mathf.SmoothDamp(thisTransform.position.y, target.position.y, ref velocity.y, SMOOTH_TIME);
             newPos.z = Mathf.SmoothDamp(thisTransform.position.z, target.position.z + offSetZ, ref velocity.z, SMOOTH_TIME);
         }
         else
         {
             newPos.x = target.position.x;
             newPos.y = target.position.y;
             newPos.z = target.position.z;
         }
 
         #region Locks
         if (LockX)
         {
             newPos.x = thisTransform.position.x;
         }
 
         if (LockY)
         {
             newPos.y = thisTransform.position.y;
         }
 
         if (LockZ)
         {
             newPos.z = thisTransform.position.z;
         }
         #endregion
 
         transform.position = Vector3.Slerp(transform.position, newPos, Time.time);
 
     }
 }

I got it from a brawler bundle, but it only works with one player. This next code comes from a YouTube hitbox tutorial, which takes in as many players needed, but does not have smooth follow and doesn't follow the Z-axis (It's designed for 2D fighters.) The lines with the z-axis was my expermenting, and doesn't actually work.

 using UnityEngine;
 using System.Collections;
 
 public class FighterCamera : MonoBehaviour
 {
 
     private Transform[] playerTransforms;
 
     private void Start()
     {
         GameObject[] allPlayers = GameObject.FindGameObjectsWithTag("Player");
         playerTransforms = new Transform[allPlayers.Length];
         for (int i = 0; i < allPlayers.Length; i++)
         {
             playerTransforms[i] = allPlayers[i].transform;
         }
     }
 
     public float yOffset = 2.0f;
     public float minDistance = 7.5f;
 
     private float xMin, xMax, yMin, yMax, zMin, zMax;
 
     private void LateUpdate()
     {
         if (playerTransforms.Length == 0)
         {
             Debug.Log("Have not found a player, make sure player tag is on.");
             return;
         }
 
         xMin = xMax = playerTransforms[0].position.x;
         yMin = yMax = playerTransforms[0].position.y;
         zMin = zMax = playerTransforms[0].position.z;
 
         for (int i = 1; i < playerTransforms.Length; i++)
         {
 
             if (playerTransforms[i].position.x < xMin)
                 xMin = playerTransforms[i].position.x;
 
             if (playerTransforms[i].position.x > xMax)
                 xMax = playerTransforms[i].position.x;
 
             if (playerTransforms[i].position.y < yMin)
                 yMin = playerTransforms[i].position.y;
 
             if (playerTransforms[i].position.y > yMax)
                 yMax = playerTransforms[i].position.y;
 
             if (playerTransforms[i].position.z < zMin)
                 zMin = playerTransforms[i].position.y;
 
             if (playerTransforms[i].position.z > zMax)
                 zMax = playerTransforms[i].position.z;
         }
 
         float xMiddle = (xMin + xMax) / 2;
         float yMiddle = (yMin + yMax) / 2;
         float zMiddle = (zMin + zMax) / 2;
         float distance = xMax - xMin;
 
         if (distance < minDistance)
             distance = minDistance;
 
         transform.position = new Vector3(xMiddle, yMiddle + yOffset, -distance);
     }
 
 }
 

So, how could I get smooth follow and a camera to follow every player in the xyz axis? Thanks!

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

0 Replies

· Add your reply
  • Sort: 

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

117 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 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 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

Multiplayer First Person Game 0 Answers

MULTIPLAYER NETWORKING 0 Answers

Unity multiplayer VR Node JS 3D 0 Answers

So I am trying to get a multiplayer system working. 0 Answers

Question on Networking for a multiplayer game (making a board game) 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