• 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
Question by Irresponsible · Mar 28, 2016 at 03:02 PM · javascriptmovement2d-platformerparallax

2D Parallax platformer

Hi guys, i'm making a 2D game, a platformer. I'm using the offset t$$anonymous$$ng to create a nice style when i walk. but... here comes the problem!

I'm trying to figure t$$anonymous$$s out by myself for a long time.

When i "get stuck" in a wall for example, the parallax effect wont stop!

Anyone could help me?

Can the linecast function help me?

if yes {
How?
} Else {
What could help me?
}

Comment

People who like this

0 Show 2
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 Cherno · Mar 28, 2016 at 05:32 PM 0
Share

You need to provide more information. "The offset thing"? how do you achieve your parallax effect? What do you mean by "the parallax effect won't stop"? Is it continually scrolling?

avatar image Irresponsible Cherno · Mar 29, 2016 at 11:21 AM 0
Share

Sorry, i'll try my best to explain. I'm brazillian, it's kinda hard to me xD

this is my problem:

https://drive.google.com/file/d/0B1eqlJRc0HcFZlRKTDUycVpNOXM/view?usp=sharing

It's a gif, ok?

Here's part of my script:

    walkDir = Input.GetAxis("Horizontal"); //get the direction of movement
     
                     if(walkDir > 0){ //if moving right...
                     MatMountain.mainTextureOffset.x += 0.05*Time.deltaTime; //the "offset thing ^.^
                     transform.Translate(walkDir * 4 * Time.deltaTime,0,0); //movement, i was using the rigid body, but changed to this.
                     anim.SetBool("andando", true); //my animations
                     }
                     if(walkDir < 0){
                     MatMountain.mainTextureOffset.x -= 0.05*Time.deltaTime;
                     transform.Translate(walkDir * 4 * Time.deltaTime,0,0);
                     anim.SetBool("andando", true);
                     }


ohh, and everything is in the FixedUpdate()

I lost like 3 hours yesterday, and couldn't figure this out...

Solving the offset would also solve my animation problem!

Thank you for answering me :D

see you.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Masterio · Mar 29, 2016 at 02:05 PM

Make a few transforms for keep layers content:

  1. layer back: slow moving transforms.

  2. layer 0: player and level transforms.

  3. layer fore: fast moving transforms.

Apply a script on layer transforms,

Pseudocode:

 layer_move_speed = 1;
 layer.position = Player.position * layer_move_speed;


Attach the script on each layer roots and change the layer_move_speed property.

Comment

People who like this

0 Show 3 · 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 Irresponsible · Mar 29, 2016 at 02:11 PM 0
Share

In this mode i would need to repeat my scene? like duplicate my mountains?

avatar image Masterio · Mar 29, 2016 at 03:16 PM 0
Share

FE: If you want to make an back layer with mountains, clouds, etc. all of that things you put under one transform called 'layer_back'. Next you are apply the move script on the layer_back transform only. Thats all.

And yes you must duplicate a mountains, if you want to repeat it, you need to work on coordinates, it is much more complex but possible to do;)

avatar image Irresponsible Masterio · Mar 29, 2016 at 10:10 PM 0
Share

Right, thank you man, thank you very much!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

(2d in 3d) Movement relative to camera using JS 0 Answers

How can I set my cube moving left and right with custom switch? 1 Answer

How to make smooth jump? 1 Answer

Can't get speed of a rigidbody. 1 Answer

Camera Script Amalgamation == Camera Script Abomination, Im In Over My Head 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