Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 XenoTracker · Sep 24, 2015 at 10:52 PM · c#2d game2dmovement

2D Movement Within a constraint (C#)

Hi I'm making a ShMUp game My player is moved using transform.position and has a box collider trigger. What are some ways I can keep the player within the constraints(In this case, in the camera's view)?

I have tried many things - adding another box collider on the player and a box collider wall (Either killed the player or he flew straight through it)

I would Appreciate All Help! Thanks

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 MikeNewall · Sep 24, 2015 at 11:09 PM 0
Share

Try moving the player with a rigid body ins$$anonymous$$d of setting the position of the transform.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by lloladin · Sep 25, 2015 at 06:09 AM

the box colliders you tryed aint working bc you are using transform.position which just moves the player instantly ignoring all collisions if you want youre player to collide with walls then moving try using Rigidbody.velocity like MikeNewall said

Example

 GetComponet<RigidBody2D>().velocity = new Vector 2(x,y);

you can also use getaxis which i would recomend since getaxis is controller supported

Example 2

 float move = Input.GetAxisRaw("Horizontal");
             movement = new Vector2(move * moveSpeed, myRigidbody2d.velocity.y);
             myRigidbody2d.velocity = movement;

heres some documentation http://docs.unity3d.com/ScriptReference/Input.GetAxis.html

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 ZalmakiZ · Sep 25, 2015 at 08:09 PM

If you want to stick with Transform.position = ... Then you Can use worldToScreenPoint(newPosition) and check if the screen point is still in view, if its outside then readjust.

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

31 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How do I stop a stopwatch/timer and display it on the end screen when the player hits the last Box Collider?,How do I stop the timer and display it on a new scene when the player hits the last BoxCollider2D? 0 Answers

Trying to reset lvl on collsion 1 Answer

Isometric diagonal movement (not 45 degrees) in a 2D game C# 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