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 Luciferous · Apr 12, 2011 at 08:19 PM · movementgravity

Loss of gravity and interation with box collider

I'm pretty much brand new to scripting, but I have been using Unity as a way to help me learn, I find having a visual result of my efforts makes retaining information easier.

Anyway I am attempting to create a basic character that will move along the x axis and I seem to have accomplished that, but somewhere along the line I have lost the characters ability to fall and interact with the object below it that has a box collider. Below is the script i am working with, can anyone see where i have gone wrong?

var speed = 1.0;

//This works fine, but lacks gravity.

function Update () { //var xPos = Input.GetAxis("Horizontal") Time.deltaTime speed; ...This is defunct script - ignore. var controller : CharacterController = GetComponent(CharacterController);

 var right =transform.TransformDirection(Vector3.forward);

 var xPos = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
 controller.SimpleMove(right * xPos);

//The below line allows the character to move, however it also prevents //the character from falling onto the ground and staying there, he floats //through the air when no geomentry is immediately below him, slowly //succombing to the effects of gravity that are affected through the above lines, why?

 transform.position.x += xPos;


 var move = Vector3(xPos, 0.0, 0.0);
 if (move != Vector3.zero) {
     var rotation = transform.rotation; 
     rotation.SetLookRotation(move); 
     transform.rotation = rotation;
 }

}

Only problem is now is that when my little guy runs up a hill when he turns to run back down it he instead floats along the x axis and slowly goes back down to the ground cube i have... Can i increase the gravity of my little guy?

Update - Tried suggestion, did not work, but through experimentation I have narrowed it down to transform.position.x += xPos ...I think it's that little ".x" that is causing the problem, but I don't know how to rephrase it without losing the movement of the character along the x axis.

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
2
Best Answer

Answer by Wollowizard · Apr 12, 2011 at 08:59 PM

add a rigidbody to it and it will get the effect your after. or add something like moveDirection.y -= gravity * (Time.deltaTime/2);

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 Luciferous · Apr 13, 2011 at 11:34 PM 0
Share

I attempted to implement your suggestion, but I couldn't get it to work, probably due to my almost total lack of coding, but I have managed to figure out what stops the character from plummeting back to the ground, see update.

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

Why can't I move along the Y axis when I shift gravity from the Y to Z axis? 1 Answer

Gravity switch 1 Answer

how to apply orbit to the player 2 Answers

Space Game (Noob Movement Question) 0 Answers

CharacterController isGrounded toggles value 2 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