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 egonspengler_84 · Apr 23, 2021 at 07:29 PM · raycastrigidbody2dtransform.translate

How would I apply gravity to a game object and have it collide with the ground beneath it by using raycasts without using Rigidbodies?

So if I had a project with two game objects that both had BoxCollider2D components attached to them one being the Player and the other the ground how would I go about appling gravity to the Player so that it would collide with the ground below it?

I thought I could apply gravity to the Player by using the the transform.Translate function in order to force the Player to travel downwards on the Y axis. While this is happening I could shoot a raycast from the bottom of the Player's bounding box so that when it hits the ground I could use the "hit" information to make the Player stop once it reaches the ground.

But I don't know how to go about doing this? Could someone help me with trying to make this work?

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
0

Answer by logicandchaos · Apr 27, 2021 at 02:14 PM

But why? Thee is built in gravity and collision. If you don't want to use rigidbodies it means writing your own physics code. Just look at how people do it in engines that don't have physics. to make it fall using translate you would have to call translate from update or a coroutine and calculate how much to move it to keep uniform motion. You could have a coroutine called fall and exit it isGrounded=true or when the raycast = true; But what are you trying to accomplish by not using rigidbodies?

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 egonspengler_84 · May 01, 2021 at 04:26 AM 0
Share

Well it's because I watched a Youtube tutorial on 2D platformers by Sebastian Lague that is highly regarding here:

https://www.youtube.com/watch?v=MbWK8bCAU2w&list=PLFt_AvWsXl0f0hqURlhyIoAabKPgRsqjz&ab_channel=SebastianLague

In this tutorial he does not use Rigidbodies at all and creates his own physics because you can achieve more fine tuning and control over your Player's movement this way according to him.......but I have no idea whether this is true or not? A lot of people seem to think it is true and that you can achieve more control by exclusively using Raycasts.

Can I ask what your opinion on this is?

avatar image FaffyWaffles egonspengler_84 · May 01, 2021 at 12:59 PM 0
Share

eyy, Sebastian Lague! hes the reason i got into deving in the first place.

while i have no experience with your particular problem, i noticed Sebastian left the source code in his video. maybe you could look into it and try to reverse engineer it?

link text

avatar image logicandchaos egonspengler_84 · May 03, 2021 at 04:26 PM 0
Share

I think you can achieve the same or relatively close fine tuning and control if you know the physics engine well, you can adjust all the gravity and mass and velocities.. I think you get the smoothest most uniform motion when you use a physics engine, but it maybe be heavier.. like if you are shooting a cannon, and creating the trajectory, if you use built in in physics you say AddForce(someVector); one line you are done! Now program$$anonymous$$g in without rigidbodies you need to calculate everything! Just seems like reinventing the wheel and makes me wonder why he is using unity and not just a graphics framework.. You can change everything about the unity built in physics, so I'm not sure how you get more fine control.. seems to be just about preference to me.. what I find is if you watch a video about the depompilation of the mario jump they say you fall faster than you rise. which isn't exactly physics correct, but it feels better. so to do this in unity with rigidbodies, you can make your own gravity force, which I have done in the past, or you can manipulate the gravity of the object. You go

 if(rb.velocity.y<-1)
     rb.gravityScale=2;
 else
     rb.gravityScale=1;
avatar image
0

Answer by adityajaix · May 03, 2021 at 05:41 PM

I am beginner as well but here what I tried simple and easy way. And it works I created an empty game object, make it child of the Character. Place it a little below it. I used set position to move towards child empty game object with a speed variable. I calculated Speed variable in a fixed update if not grounded set speed = speed + rate float variable. and if grounded set speed to 0. try changing rate to make acceleration slow or fast.

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.

Follow this Question

Answers Answers and Comments

170 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to move using translate.transform a hinge joint with motor turned on? 0 Answers

Weird raycasting behaviour with rigidbody objects 1 Answer

Make an object that moves relative to the touch more natural 0 Answers

Raycast 2D 0 Answers

Improve ray detection? 0 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