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 Seyyed · Dec 13, 2012 at 05:30 PM · movementmoving

Simple Movment

i am new to unity, how can i create a simple movement for an object that don't sink to other objects while moving?

i've add Rigidbody and BoxCollider to them all.
i wrote this and attached them to the object

var s = 5;
function Update () {
if(Input.GetKey ("up")){
transform.Translate(0,0,s);
}
if(Input.GetKey ("down")){
transform.Translate(0,0,-s);
}}

The problem is that When the player collisions another object, it sinks into the object a little and if I hold the arrow key down, the player sinks into and comes out from the object regularly.
It leads the camera which is behind the player, to go back and forth regularly. How do I solve this problem?

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 GooseNinja · Dec 13, 2012 at 06:01 PM 0
Share

What language are you using? What type of object is it? What are you trying to do?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by danilonishimura · Dec 13, 2012 at 06:09 PM

Hi Seyyed.

I suppose you're trying to make a simple adventure game. First, check if your object has a collider (BoxCollider, MeshCollider, whatever). Then, add a RigidBody to your object (menu: Physics > Rigidbody). Then attach a script to your object who will access the Rigidbody and add forces accordingly to your needs. You may also freeze each axis rotation and/or position on the Rigidbody component (ie: you'll want to freeze the z position if you're trying to make a 2D adventure game).

Comment
Add comment · Show 1 · 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 Seyyed · Dec 13, 2012 at 07:13 PM 0
Share

thank you danilonishimura but i knew that! (i said "i am new" not "much new!" :) ) now tell me about the script. what i have to write?!

i wrote this and attached them to the object

var s = 5; function Update () { if(Input.Get$$anonymous$$ey ("up")){ transform.Translate(0,0,s); } if(Input.Get$$anonymous$$ey ("down")){ transform.Translate(0,0,-s); }}

i have add Rigidbody and BoxCollider to them all. The problem is that When the player collisions another object, it sinks into the object a little and if I hold the arrow key down, the player sinks into and comes out from the object regularly. It leads the camera which is behind the player, to go back and forth regularly. How do I solve this problem?

thanks!

avatar image
0

Answer by GooseNinja · Dec 13, 2012 at 08:18 PM

Have you put constraint on rotation in the rigidbody component?

Try changing the variable to

 var s = 5.0;

And also try changing your code to

 if(Input.GetKey ("up")){
 transform.Translate(Vector3(0,0,s) * Time.deltaTime);
 }
 if(Input.GetKey ("down")){
 transform.Translate(Vector3(0,0,-s) * Time.deltaTime);
 }
Comment
Add comment · Show 1 · 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 Seyyed · Dec 14, 2012 at 06:08 AM 0
Share

yeah, i freezed x,y,z of rotation in Rigidbody
I've tested your code but still not working and the player sink a few in other objects
i have an idea:
before the "up" code, check there is any object in front or not, if there isn't anything, let the player to moving forward
any solution?

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

11 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

Related Questions

Rotation and movement? 1 Answer

Making a bubble level (not a game but work tool) 1 Answer

Third Person Controller Rotation 0 Answers

Movement in mid air 3 Answers

Moving character....northwest...? 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