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 GTS925 · Oct 12, 2010 at 12:38 PM · colliderfollowwallcollide

Help, Sphere goes through the Wall!

Okay, in this project I have a wall, a sphere, a box and a base. So the wall is in the middle of the base and the box is placed behind it. What I want to happen is for the sphere to go around the wall so that it could stand next to the base. The problem is, it won't go around the wall, it goes through it, and I already put the colliders in them.

This is the follow code which I got from here. var target : Transform; //the enemy's target var moveSpeed = 3; //move speed var rotationSpeed = 3; //speed of turning

var myTransform : Transform; //current transform data of this enemy

function Awake() { myTransform = transform; //cache transform data for easy access/preformance }

function Start() { target = GameObject.FindWithTag("Player").transform; //target the player

}

function Update () { //rotate to look at the player myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);

//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

}

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
1

Answer by jjobby · Oct 12, 2010 at 01:14 PM

It goes through the wall because you change its transform position directly. You should add sphere collider and rigidbody to it and then move it by using Addforce instead. From the code, if the sphere is just physics object in your scene (no AI, no control) then these codes shouldn't be needed.

var target : Transform;

target = GameObject.FindWithTag("Player").transform;

Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);

But in case that the sphere is moving too fast and still goes through the wall then you should try to change collision detection option in rigidbody.

http://unity3d.com/support/documentation/Components/class-Rigidbody.html

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 Crafty Firefox · Oct 12, 2010 at 01:19 PM

This might be because you are telling your sphere to do so :).

I suppose you want the sphere to go around the wall using a physics simulation. For that, you need to:

  • add a rigidbody to the sphere
  • add a spherecollider to the sphere
  • add a BoxCollider to the wall you wish to go around
  • use FixedUpdate (as for all physics manipulation) instead of Update
  • use AddForce (clean) or set the velocity of the sphere's rigidbody for movement

you will need to play around with the values for mass and force, until you achieve the desired effect.

Alternatively, you could use a pathfinding-approach (forgetting all of the above about physics) using e.g. A* and define your nodes for the A* in 3D-Space (or pseudo-3D, locking down y coordinate), doing a more or less (depending on implementation of course) smooth transition between the path you found. You will of course need to implement that yourself, there is no "out of the box" logic in Unity for that.

Of course, there is many more ways to "move a sphere around a wall to an object behind it" - but this completely depends on what you want to do, which you don't state so far ;).

Without any further detail, that's the pointers I can provide, hope they help.

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 Aowal · Dec 28, 2014 at 06:24 AM

I think this might help:

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

1 Person is following this question.

avatar image

Related Questions

Object collision 2 Answers

Player's Collider Stuck Help 1 Answer

My script says object is not colliding with the tag! But it is! 1 Answer

camera goes through walls n objects etc 1 Answer

Turn an objects mesh renderer on upon collision. 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