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 Ximpulse · Apr 28, 2011 at 04:18 AM · movementcharacteruce0001

Movement In World axis Not object axis.

Hi, I'm a 3D artist working on a small project, and note I said artist. I'm in no way shape or form a programmer, I just started learning Javascript about a week ago. Anyway I'm working on a 2.5D Project And i have the Character rotating With the mouse Location. However when the character moves It's relative to The characters axis so he moves in whatever direction he is facing. I'm looking for A very simple script to make it so No matter what direction the character is facing, The movement will always be in the same direction. now and this is most likely very incorrect. but i figured it would be something like this.

Blockquote

Blockquote> function Update() {

   Input.GetAxis("Horizontal") * Time.deltaTime * speed, Space.World;
 Input.GetAxis("Vertical") * Time.deltaTime * speed, Space.World;
}   

} Blockquote

Blockquote

But this keeps coming back with a expecting ";" error on line 6 and 7 so i am very confused. mainly because i have almost no knowledge of this language

I am just trying to do this until My Programmer Can understand exactly what the project is going for.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kourosh · Apr 28, 2011 at 04:30 AM

1.Create an empty game object, name it "Direction" and rotate it so that the z axis (forward) is facing the direction you want.

2.Attach the script bellow to your character:

var fixedDirection:Transform; //drag 'n drop the "Direction" game object to this slot. var speed:float = 1.0; //Change to whatever you want. function Update(){

transform.Translate(fixedDirection.forward Input.GetAxis("Vertical") Time.deltaTime speed); transform.Translate(fixedDirection.right Input.GetAxis("Horizontal") Time.deltaTime speed);

}

I haven't tested it tho. But it should work.

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 Ximpulse · Apr 28, 2011 at 04:53 AM 0
Share

I't doesn't work along side of my mouse look script. Which is

ar speed = 4.0;

function Update () {

 var playerPlane = new Plane(Vector3.up, transform.position);
 var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 var hitdist = 0.0;

 if (playerPlane.Raycast (ray, hitdist)) {

     var targetPoint = ray.GetPoint(hitdist);
     var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);

     transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
 }

}

It Works fine on its own though.

avatar image Kourosh · Apr 28, 2011 at 05:04 AM 0
Share

Ye cause both scripts are trying to manipulate the character at the same time. Here is the solution. You need another empty game object and parent your character under it. Assign the script I wrote here to the parent ins$$anonymous$$d of the main character itself.

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

Platformer character movement 0 Answers

How would I make a character flatten against a wall? 0 Answers

How to handle walls with my FirstPersonCharacter? 1 Answer

How to prevent rigidbody with capsule collider from walking off the edge of cube mesh if button held down? 1 Answer

Non-symmetrical Character walk left animation. 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