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 gopics · Sep 11, 2014 at 12:48 PM · raycastterrainflyingdown

using Raycast.hit function my car gets up and doesnt gets down ? it is in flying state

hai everyone...iam new to unity...am trying to move a car in a terrain surface(mountain).using raycast.hit function i get my car up when am hitting in the mountain surface..but my car doesnt gets down...the position of the car cannot be rest to terrain i,e ground....here is my code...Thanks... car moving script..

 public float movespeed=300;
 public float turningSpeed=40;
 start(){}
 void update(){
 float horizontal=Input.GetAxis("Horizontal")*turningSpeed*time.deltaTime;
 transform.rotate(0,horizontal,0);
 rigidbody.addforce(input.getaxis("Vertical")*movespeed*transform.right)
 }

this is my raycast codings...

 public class finddistance
 {
 public Transform target;
 void start(){}
 void FixedUpdate(){
 RaycastHit hit;
 if(physics.Raycast(transform.position,-vector3.down,out hit)){
 float distanceGround=hit.distance;
 float heightToAdd=transform.localScale.y;
 target.Translate(0,transform.position.y-distanceGround+heightToAdd,0);
 }
 }

pls ignore the cases of the letters....and i dont have any colliders in my project.

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 Tricky7991 · Sep 11, 2014 at 05:04 PM

If I am understanding your question correctly. Basically you want your car to raise and lower in height depending on the height of the ground?

If so then all you would need to do is divide the distanceGround by 2.

  target.Translate(0,distanceGround / 2,0);

And it should always bring you to the same height you where before. Unless you have multiple mountains in a row touching each other at different heights

Comment
Add comment · Show 3 · 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 gopics · Sep 12, 2014 at 08:14 AM 0
Share

sorry thar dived by 2 method is not working........

avatar image Tricky7991 · Sep 12, 2014 at 05:42 PM 0
Share

What does it do? And give some more info. Like height of mountains, and the values of the transform.position.y

avatar image gopics · Sep 15, 2014 at 07:38 AM 0
Share

sorry cannot findout the height of the mountains...dont know how to find out......and transform.position.y value changes every time......

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

using Raycast.hit function my car gets up and doesnt get down ? 0 Answers

Instantiated Objects not being set at ground/terrain level?(Solved) 1 Answer

Building placement validation on curved terrain 0 Answers

How to get the y coordinate of a point based on the x and z coordinates 2 Answers

How to get Vector3.down in world space? 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