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 PixelMuncher · Nov 20, 2010 at 03:15 AM · 2drotationjavascriptmovement

Locking move direction and rotation in JavaScript

Hi all. I'm new to unity and all of my (limited) experience in JavaScript has been either for web development or 2D flash games so I'm having some difficulties with the scripting. I finally finished all the different enemy ai scripts and they seem to be working wonderfully with the exception of one problem: I foolishly programmed them for a 3D environment when it's for a 2D project. The project I am tinkering around with is a top-down vehicle combat game. With this being the case I want my enemies to only move in the X and Z directions and rotate about the Y-axis. Also, a lot of my scripts use "transform.LookAt(target);" This is also a problem as the player and the enemies (through the use of waypoints) are going up and down ramps to different elevations causing enemies to look up and fire at the player. I was hoping for some suggestions for how I could lock the move direction and rotation (preferably through script).

Although, I will say in my defense that when I started programming the AI I didn't know what kind of project I wanted to do. Only after half the scripting was done did I realize I wanted to do a top-down shooter. ^_^''

Sorry for the long question. Any help would be greatly appreciated.

Comment
Add comment · 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 Jesse Anders · Nov 20, 2010 at 04:17 AM 0
Share

If the characters can go up and down ramps and be at different elevations, etc., isn't it actually a 3-d game, more or less? Or am I misunderstanding?

avatar image PixelMuncher · Nov 20, 2010 at 04:40 AM 0
Share

Technically this is a 3D game. However, with the camera position and player controls it plays more like a 2D game. The main reason there are different elevations is because there are bridge like segments where the player and enemies can either go under or over the bridge. I want to be able to do this without having enemies on the ground being able to look up and fire at the player, especially considering that I have it set up so the player can only fire in the X and Z directions and not up or down.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Uriel_96 · Nov 20, 2010 at 05:03 PM

for me is more easy to put on the X and Y axis but if you are doing something like he cant go up or down(to use only the X and Y axis) you can use to all that you have something like this:

transform.Translate(transform.forward * Time.deltaTime * speed,Space.World);//or use
transform.Translate(transform.right * Time.deltaTime * speed,Space.World);

or many other several things you can do and for going down or up you only put the gravity(rigidbody). And with this you can use it with several things(using forward or right)or better you can use Vector3.forward or Vector3.right, and for going backwards you use -Vector3.forward and for left use -Vector3.right

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Erratic behaviour during rotation 1 Answer

2d Movement Messes up when cube is rotatated 0 Answers

Problem changing 3rd Person controller rotation 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 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