• 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 Oudaiesty · Feb 22, 2010 at 11:34 PM · physics

Simple Slide based movement down a hill

I'm a new unity user (pretty much brand new) and I'm working on scripting a natural yet controllable sled-like motion down a slope. Its kinda like Bowling in a sense. I wanted to implement physics going down the hill so that the acceleration is controlled by gravity. Heres an attempt that I whipped up after looking at some controller script examples that aren't quite what i've been looking to do(some variables haven't been used yet):

var speed = 3.0; var jumpSpeed = 8.0; var gravity = 10.0;

var smoothSpeed = 10.0; var smoothDirection = 10.0;

var canJump = true;

private var moveDirection = Vector3.zero;

private var moveSpeed = 0.0;

private var grounded : boolean = false; private var jumping : boolean = false;

private var verticalSpeed = 0.0; function Update () {

 var sideForce = Input.GetAxis ("Horizontal") * sidewaysPush;
 var rotation = Input.GetAxis ("Horizontal") * rotationSpeed;
 rigidbody.centerOfMass = Vector3 (balancePoint.x, balancePoint.y, balancePoint.z);

 transform.rotation.y = Mathf.Clamp(transform.rotation.y, -80.0, 80.0);



 // Make it move 10 meters per second instead of 10 meters per frame...
 sideForce *= Time.deltaTime;
 rotation *= Time.deltaTime;


 constantForce.force.z = sideForce;
 transform.Rotate (0, rotation, 0);

}

I do also plan to allow jumping but for now I wanted to get the basic movement down. I just can't seem to get good control over the direction that I turn nor can I seem to control the rotation of the attached rigid body. The best thing I tried was to change its center of mass, it helped but now when I hit walls I end up with an unrealistic rotation if I separate from the ground.

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 Sebas · Feb 22, 2010 at 11:40 PM 0
Share

This answer might help you getting started (http://answers.unity3d.com/questions/4430/camera-and-physics-controls-for-sledding-styled-game)

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Motionreactor · Feb 23, 2010 at 04:41 AM

This is a partial answer to the rotation problem.

Try using AddTorque() or AddRelativeTorque() to affect the rotation of a rigidbody rather than changing the GameObject transform directly.

rigidbody.AddRelativeTorque(0, -10, 0);

Something like that. Be aware that the center of mass will affect the result of course.

http://unity3d.com/support/documentation/ScriptReference/Rigidbody.html

Also note that with physics, ie Rigid Bodies you should use FixedUpdate() rather than Update() because FixedUpdate() is fixed to the physics integration steps for consistent behaviour.

I hope that helps.

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 Ashkan_gc · Feb 23, 2010 at 05:11 AM 0
Share

it's a good practice to link names of functions to their documentation page.

avatar image Motionreactor · Feb 23, 2010 at 12:36 PM 0
Share

I did, to the RigidBody reference. Because I'm a new user I couldn't post more than one URL.

avatar image
3
Best Answer

Answer by Ashkan_gc · Feb 23, 2010 at 05:17 AM

use a rigidbody and AddForce method to move it in the way that you want. change the friction values to have the kind of movement that you want. you can use AddTorque if you want to rotate the ball more. sometimes when you rely on gravity to move your ball you don't get what you want. you can edit the gravity in edit/project settings/physics. size your bjects correctly. don't use a collider with radius of 0.5 if you don't want a huge ball.

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 runevision ♦♦ · Feb 23, 2010 at 09:33 AM 0
Share

The size of the ball doesn't matter if you just remember to adjust the physics settings accordingly. For example if you ball has a radius of 0.5 and you want it to be 1 cm (not 1 meter) then you just need to change the physics settings values to be measured in cm as well. Of course, it is probably easier to just keep the default settings and model things in meters, but it's definitely not mandatory.

avatar image Oudaiesty · Feb 23, 2010 at 09:12 PM 0
Share

I couldn't use torque since my object isn't a ball but this information might be just what I needed. If I used global force would it cause problems if the courses didn't all flow in the same direction? (Just incase a 3D artist didn't know that and they put them in there in any direction that it was defaulted to) I'm going to give this a go definitely.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

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

Im having a Problem with Basic Collision. 1 Answer

How do I break apart an object? 2 Answers

Finding the axis of a curving pipe 0 Answers

Manual collision check 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