Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Gutovysk · Sep 23, 2011 at 11:57 PM · collisionterrainhitfirst person controller

First Character and loose hit points

Hi everyone,

I'm new in unity3d and i'm trying to do something to understand.

I did a terrain with mountains and rocks, and I want to move and jump my character (first person) around the world.

So, I want to loose "hit points" (health) when they hit with high velocity.

For example, if I jump and hit a rock or on the ground too distance, I must loose health or die (if the collision is strong!).

I`m use the Standard Prefab First Person Controller, and if I put rigidbody component in it, the controller did´nt work well!

Any suggestions?

tks

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 ocularcash · Sep 24, 2011 at 12:37 AM

the first person controller that comes with unity has alot of bugs when you attach a rigidbody. Here's a simple script you can use as a move script. just add this script to whatever you want as a character and go to component/camera-control/mouse look and add it and also go to component/physics/character controller and add it.

public var MoveSpeed : float = 50;

public var jumpSpeed : float = 55;

public var MoveDirection : float = 45;

public var grounded : boolean = false;

function Update(){

        if(grounded){

                  MoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

                  MoveDirection = transform.TransformDirection(MoveDirection);

                  MoveDirection *= MoveSpeed;

        }

        if(Input.GetKeyDown(KeyCode.Space))

         {

                   MoveDirection.y = jumpsSpeed;

          }

}

MoveDirection.y -= Gravity * Time.deltaTime;

var Controller = GetComponent(CharacterController);

var Flags = Controller.Move(MoveDirection * Time.deltaTime);

grounded = (Flags & CollisionFlags.CollidedBelow) !=0;

}

as for hit points per speed you would actually have to adjust the script by adding drag to just about everything so that you would be moving different speeds depending on how long the button is held, released, gravity and adding a top speed for acceleration and gravity. Maybe using something like if force = a certain amount then -- hitpoints. sorry i can't be too helpful on that

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 syclamoth · Sep 24, 2011 at 02:22 AM 0
Share

Or, you could do the smart thing and switch to using rigidbodies ins$$anonymous$$d. The Character-Controller is nice for prototypes, but as soon as you start to need physics for anything, they become extremely difficult to code for.

avatar image Gutovysk · Sep 24, 2011 at 05:57 PM 0
Share

Yes. I`ll try. But how i know the speed that the character hit something? For example, what function i use to know the relative speed betwen the character and the ground when he falls in abysm?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Collision Problem - Terrain collider remains flat after raising or lowering it 0 Answers

Generated Terrain not colliding! HALP. 0 Answers

Hitting people by a car 3 Answers

Is there any equivalent to composite collider in 3d 0 Answers

Having an array of points(vector2), how do I create a 2d terrain? (new to unity) 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