Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 SandjeMandje · Apr 14, 2011 at 03:05 PM · rotationcamera-movement

Double Dragon style Camera and movement

Hello guys, hope you can help me. I'm making an old arcade style game, where the character walks on 2 axes, the x and z, and jumps up. The movement works fine now. I can walk left of the screen and to the right and up and down the street.

The problem is however, that i want my character to rotate to the left (180 degrees) and back when i go to the right (kinda like strafing up and down, so that the rotation is always 180 degrees or 0 when walking the other way). When i use the scripts i found on the web, the character just rotates to the direction i'm walking toward, wich is not what i want.

The other problem i'm having, is that when i rotate the charater, the camera (attached to the player character) rotates with it.

Help is really appreciated guys.

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 burnumd · Apr 15, 2011 at 01:32 PM 0
Share

If you crosspost to the forums, please link to the other location as well, so efforts aren't duplicated. http://forum.unity3d.com/threads/85837-Double-Dragon-style-Camera-and-movement

4 Replies

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

Answer by FrHaYwOrKs · Apr 14, 2011 at 03:24 PM

For what matters the first problem I don't really understand what you mean, why wouldn't you have the character rotating where you are walking to? Where should it rotate instead?

For what matters the camera problem, maybe you should use a script on the camera itself to follow your character, instead of linking it to the moving objects, since it can rotate and it would be harder to re-rotate the camera every time!

Try something to follows the object... like:

var character : Transform; var offset : Vector3 = Vector3(0, 0, -10);

function LateUpdate () { var newPosition = Vector3(character.position.x, character.position.y, character.position.z); transform.position = newPosition + offset; }

And then set up the offset to what you like more to follow the character from the right camera position!

Comment
Add comment · Show 4 · 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 SandjeMandje · Apr 15, 2011 at 07:29 AM 0
Share

For the movement i wanted to use a old style movement. Because the older games used sprites, they could move more then 180 degrees, and back. So thats kinda what i want to recreate. I want them to move to where they are looking, but only on a straight line. So kinda like a 2D sidescroller, yet the movement is not restricted to just 2 axes, only the rotation is restricted.

avatar image FrHaYwOrKs · Apr 15, 2011 at 07:36 AM 0
Share

I must admit I have no idea on how this could be accomplished right now... :(

avatar image SandjeMandje · Apr 15, 2011 at 07:49 AM 0
Share

Thanks for the camera script btw, works like a charm!

avatar image FrHaYwOrKs · Apr 15, 2011 at 07:50 AM 0
Share

You're welcome! :D

avatar image
1
Best Answer

Answer by loopyllama · Apr 15, 2011 at 08:19 AM

When you update the position, store it in a variable called something like lastPos at the very end of the update. That way you can grab the Mathf.Sign of transform.position.x - oldPos.x. That is your left/right direction, a 1 or -1. If you are using sprite, just flip the uvs. Then you do not have to worry about the camera since you are editing uvs. If it is a 3d character set the transform.eulerAngles.y to 180 if the sign is -1 or 0 if the sign is 1. For the camera rotation problem if it a 3d character..you probably have your camera as a child of the player. Do not do this. Unparent the camera and character. Make the camera's x and y transform.position = character's transform.position. Leave the z position of the camera alone.

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 SandjeMandje · Apr 15, 2011 at 03:08 PM 0
Share

When i set the rotation to 180 degrees, he seems to be doing this continuously as long as i'm holding down a direction. So when i'm holding down left, he keeps turning like a maniac :D. Any suggestions?

avatar image loopyllama · Apr 15, 2011 at 03:31 PM 0
Share

yeah make sure you are only checking the left right dimension, be it x or z, and base your rotation on only that dimension. also, post the relevant code if that doesn't work...

avatar image
0

Answer by Aurelio Provedo · Apr 15, 2011 at 07:54 AM

For the rotation, just create a temporary Vector3 and assign it the character's speed, then set its Y to zero, and use this vector for rotation. Something like this:

var rotateDir = mySpeed; // Or myDirection, whatever you're using.
rotateDir.y = 0;
rotateDir.Normalize();
if ( rotateDir.sqrMagnitude > 0.01)
    transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (rotateDir), Time.deltaTime * rotationSmoothing); // rotationSmoothing should be an attribute of the script. 

For the camera control, I advice you to look at the 2d platformer tutorial, if you haven't done so already. I believe you could just take the camera scripts there and put them in your game, it should work just fine. You'll find more useful stuff in that tutorial, too.

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 SandjeMandje · Apr 16, 2011 at 09:55 AM

Fixed the movement now. I used a Tutorial for a previous style movement. When i was trying this, i forgot that i needed to remove the line "moveDirection = transform.TransformDirection(moveDirection);". So that line was transforming my direction when ever my rotation was different. D'oh.

For the controlls i'm using this now:

if (transform.position.x < lastPos){ transform.eulerAngles = Vector3(0,180,0); lastPos = transform.position.x; }

     if (transform.position.x &gt; lastPos)
 {
     transform.eulerAngles = Vector3(0,0,0);
     lastPos = transform.position.x;
 }

So that fixes it. Thanks every one!

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

Why is my camera not snapping 90 degrees? 0 Answers

Floats not being applied? 1 Answer

Flip over an object (smooth transition) 3 Answers

Swipe angle and Rotation of camera to movement 1 Answer

i need to use the rotation value of the x axis on a camera 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