• 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 Ali · Jun 12, 2010 at 07:49 PM · collisionground

Input when not in contact with floor

Im making a skateboarding game at the moment for a college project, i have a couple of inputs to control and flip my board, but i dont want to be able to use the input to flip my board while in contact with the floor but i cant figure out the script to do this, i have the script to flip the board but i only want to be able to use it once my skateboard is in the air. would be much appreciated if anyone could help.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tetrad · Jun 12, 2010 at 08:14 PM

How to properly answer this will depend on how you set up everything else. If you're using a character collider for movement, the FPSWalker script has an example of how to determine if you're on the ground (off the top of my head, it's something like checking to a bit flag off the return value of .Move()). If you're using wheel colliders on your board, you can use the isGrounded property to just ask if it's on the ground or not.

One thing you could do regardless of anything else, is every frame do a Physics.Raycast to determine if you're on the ground or not. Trace from the player or board or whatever downward, and see if you hit the floor. If you make your ray length pretty small (say, the height of a skateboard wheel), then the question simply becomes "did raycast hit anything".

I'm assuming you can figure out how to turn off your in-air trick input once you can answer the question "am I on the ground".

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 Ali · Jun 12, 2010 at 08:25 PM 0
Share

Thankyou for replying but my in-air trick isnt actually an animation, its done by just transform rotate if you know what i mean. so i was wondering if there is anyway to script it so it would be like, if in contact with collider/rigidbody input false?
haha i have no idea :P

avatar image Tetrad · Jun 12, 2010 at 09:05 PM 0
Share

Well just use what I talked about, and wherever you do whatever your trick is, just wrap that with if( IsPlayerInTheAir ).

avatar image
0

Answer by JonManatee · Jun 12, 2010 at 08:24 PM

If you are using a character controller you can structure your controller.Move call to be like this:

CollisionFlags flags = controller.Move(velocity * Time.deltaTime);
if ((flags & CollisionFlags.Below) != 0)
    grounded = true;
else
    grounded = false;

grounded will be true when the character is in contact with the ground.

Alternatively, there is also a characterController.isGrounded property, however some of Unity's resources show that the characterController's built in properties can be unreliable at times (namely the scripts in the Character Animation Example Project).

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 Rennat · Dec 01, 2010 at 10:32 AM

You will need to determine whether or not your skateboard is touching the ground.

private groundHitCount : int = 0;

function OnCollisionEnter (collision : Collision) { // Determine if it's a ground hit (using tags or vertical raycasting) ++groundHitCount; }

function OnCollisionExit (collision : Collision) { // Determine if it's a ground hit (using tags or vertical raycasting) --groundHitCount; }

function AmIGrounded () { return (groundHitCount > 0); }

function Update () { if (AmIGrounded()) { // Ground input here } else { // Air input here } }

Making this up as I go but hopefully it at least gets you started.

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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Can someone help me fix my Javascript for Flickering Light? 6 Answers

bullet decals have wrong rotation C# 2 Answers

Send Raycast to ground, place player at Raycast hit? 1 Answer

Ignore collision on tag not working 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges