• 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 jesseoffy · Feb 20, 2010 at 06:13 PM · cameraphysicscharacterview

Camera and Physics controls for sledding-styled game

I am very new to Unity, but I have a background of using dim3 engine a bunch. I have been trying to make a camera script that I could use on a sled character. My goal is to have the camera's POV be that of a person riding the sled (so it would see the tip of the sled and still be glued to the sled model), but I don't know how to set this up. I also would like to know how to make an acceleration type of movement where after I start pressing a forward button, the character (sled) continually increases in speed until, for example, I press another key to "apply brakes" (i.e. slow it down again). Could anyone be so kind as to help me set this up? I think once I get this camera script down the rest would be a bit easier (already tried making tracks/ colliders.)

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

2 Replies

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

Answer by duck · Feb 20, 2010 at 08:04 PM

To make a camera seem "glued" to an object, the simplest way is to parent the camera to the object, by dragging it on to the object in the hierarchy. This way, whenever the parent object is moved (the sled), the camera will also be moved.

To allow keyboard controls to affect the movement of the sled, you need to ensure the sled gameobject has a collider and a rigidbody component attached. You probably should then apply the "Ice" Physic Material to both the sled and the terrain or ground object. This will allow the sledge slide easily down slopes.

Usually when writing games using the physics engine, you'd want to add forces to the player object using AddForce in your FixedUpdate function, however in your specific case it might be enough to simply modify the drag of your rigidbody. If you're on a hill, and you've applied the Ice physic material to the objects, then setting "drag" to zero would be like allowing acceleration, and setting "drag" to a higher value would be like braking.

You could implement this using a script something like this:

var originalDrag : float;

function Start() { originalDrag = rigidbody.drag; }

function FixedUpdate () { var control = Math.InverseLerp(1, -1, Input.GetAxis("Vertical")); rigidbody.drag = Mathf.Lerp(0, originalDrag*2, control); }

The script above uses the vertical axis input (your forward and backwards arrow keys), and adjusts the drag based on that input.

When pressing forward, there will be zero drag, and when pressing backwards there will be double the value of drag specified in the editor. When not pressing anything, the editor value is used. This means you can tweak the "drag" value in the editor until your sledge runs at an acceptable speed, while still being able to control it via your script.

Hope this is something near what you're looking for!

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
avatar image
0

Answer by jesseoffy · Feb 20, 2010 at 08:49 PM

Ok, I think I get it, but I'm getting confused by your script example and the "Ice Physic material". I found the physic material, but I am assuming by calling it "Ice" you just intend for me to call it "Ice" and change settings of friction accordingly.

In the drag script you posted above, is that supposed to be placed in a script like the FPSWalker, or by itself?

Here is a picture of what I got so far following your explanation and my own variation... hope it is decently correct. :)

http://img97.imageshack.us/img97/1296/screenshot20100220at348.png

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 Lipis · Feb 20, 2010 at 10:55 PM 0
Share

If you want to reply on the answer you should make a comment rather than a new answer..

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

Check object is inside a "simulated" camera view 1 Answer

My Scene is messed up? 1 Answer

How to get a screenshot in game and re-use in game? 1 Answer

Smooth Camera Movement script with problem. 0 Answers

Camera shows objects in wrong order 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