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 SomeGuy22 · Nov 19, 2012 at 01:23 AM · camerainputplayermovelocalposition

Directional Movement - Input position calculation?

Hey sorry if it's hard to explain but basically I want to have an empty target at the player position and have it move according to the directional buttons, but also according to the camera. The thirdpersoncontroller tries to do this but the system is really bad and doesn't account for sideways movement.

Here's a picture of what I'm trying to achieve:

edit: down below

Basically a movement system according to the camera. I tried using this script, but localPosition on both objects are starting to confuse me:

 var p : Transform;
 var cam : GameObject;
 
 function Awake () {
     
     if (!cam)
     cam = gameObject.FindWithTag("MainCamera");
 }
 
 function Update () {
     
     transform.rotation = cam.transform.rotation;
     transform.position = p.transform.position;
     
     if (Input.GetAxis("Horizontal") > 0)
     {
         if (Input.GetAxis("Vertical") > 0)
         {
             transform.localPosition = Vector3(p.transform.localPosition.x + 1, p.transform.localPosition.y, p.transform.localPosition.z + 1);
         }
         }
         //etc
 }

I'm not sure if that's what I'm supposed to be doing, but that's the target script... that doesn't work. Is there an easier way to get directional keys according to the camera with the center point being the player?

alt text

idea.png (67.1 kB)
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
0
Best Answer

Answer by SomeGuy22 · Nov 19, 2012 at 10:19 PM

Solved it.

You need to have a center point on the player with the camera's rotation, and have a child of that object that's local position = Input.GetAxis.

Then you have the player always move forward and have him point towards the local object.

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 diegzumillo · Nov 19, 2012 at 03:41 AM

IF I understood your question, here's how I would do this:

Create a dummy object, let's call it 'root'. As a child of this root I would assign a camera and, maybe, a model for the player, but let's keep it simple and just work as if root is the player model already.

The camera isn't at the same position of the root, but flying above it. Assign a script to the camera that makes it always looking at the root. At the root assign a script that rotates it around the y axis according to mouse movement. Also at the root assign (with the same script, if you like) movement using the regular fps movement. Since the root is actually rotating, when you tell it to go forward in its local coordinate system it will be coherent with the camera as well.

If you don't want the player model to always have his back at the camera, make it a child of root and tell it to follow the root.

Comment
Add comment · Show 2 · 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 SomeGuy22 · Nov 19, 2012 at 10:09 PM 0
Share

Sorry that's not what I meant, I wanted to make it so the player could move backwards and sideways on the camera and still have movement based on the camera. I think I might have figured this out, if so I'll post an answer later.

avatar image diegzumillo · Nov 19, 2012 at 10:18 PM 0
Share

Sorry for not being able to help you. If your solution ends up not working try to elaborate your question a little better, maybe I or someone else can help you.

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

10 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

Related Questions

How to make a camera that moves with the player? 1 Answer

3rd person player 0 Answers

Cinemachine Input Provider requires InputActionReference. Any workarounds? 0 Answers

Problems with the movement of the player 1 Answer

Player move and camera problem 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