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 /
  • Help Room /
avatar image
0
Question by Joebear · Dec 21, 2015 at 01:13 AM · c#javascriptrigidbodyrigidbody-collisionpassing thru

A script that doesn't allow moving objects to go through non-moving objects?

I have a player, a zombie, and walls. The player does not go through walls or the zombie. The zombie goes through walls. Movement script:

 var target : Transform;
 var moveSpeed = 20;
 var rotationSpeed = 5;
 var myTransform : Transform;
 
 function Awake() {
         myTransform = transform;
 }
  
 function Start() {
  
         target = GameObject.FindWithTag("Player").transform;
 }
  
 function Update () {
    
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
     myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
 }

I no longer care what the script is, as long as it works. Can someone please respond?

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 Statement · Dec 21, 2015 at 01:36 AM

I suggest you reuse the movement script from the player as it already works as intended.

Then, make the zombie control the movement script to navigate toward the player, and make sure your player has a script that control the movement script on the player.

  • PlayerInput directs Movement script on Player game object

  • ZombieAI directs Movement script on Zombie game object

  • I guess your Movement script already controls a rigidbody or something, so make sure both the Zombie and Player have the necessary colliders and rigidbodies and whatever else it needs.

It sounds like movement is pretty much the same with the thing that differ being input method. One is algorithmic (Zombie) and one is driven by input (Player). Makes sense?

Comment
Add comment · Show 4 · 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 Joebear · Dec 21, 2015 at 03:11 AM 0
Share

The movement script for the player was an imported package from the Standard Assets folder in the Asset Store. As I am not familiar with that script, I'm not sure I can successfully alter it in any way. It also takes into account a head bob and a jump. Would a DontGoThroughThings alternative simply be an OnCollisionEnter > (move back a bit) also be sufficient? I would have to research some more, but would that be possible?

avatar image Statement Joebear · Dec 21, 2015 at 11:50 AM 0
Share

Sure, but you could also capsulecast ahead of you before you move too. It gets a little tricky to make something like "OnCollisionEnter > (move back a bit)" because it'll mean you can't slide along walls (Like with capsule cast: if you are about to touch anything, you won't move forward. Like with your proposal: if you touch anything, you will move backward)

To slide along walls, you need to get the normal of the contact and figure out the slide from there. And by the way, if your world has complex geometry, be careful when you "push back out" or "apply sliding" to not slide through yet another wall.

avatar image Statement Joebear · Dec 21, 2015 at 11:55 AM 0
Share

I guess its up to you to decide to familiarize yourself with the standard asset scripts to see if it is modular already or if you should use rigidbodies (that automatically deal with collision) or make your own physics response calculation. I dunno which saves you most time and trouble, but going with something that already works sounds like a good place to begin, to avoid creating something that might be buggy if not done properly.

avatar image Joebear Statement · Dec 23, 2015 at 04:36 AM 0
Share

I get what you're saying, but the "OnCollisionEnter>(move back a bit)" was actually a last resort. They both have rigidbodies already. I'll try my own script to see if it really works well. The only real thing I'm trying to do right now is avoid defying physics. Thanks

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

50 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

Related Questions

Stopping Moving Objects? 0 Answers

Trigger activating before entering trigger. What do I do? 0 Answers

Jump is higher then normal 0 Answers

how can I add Sprint into my Script ?,How can I add Sprint function ?? 0 Answers

3D Trajectory Prediction 3 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