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 /
This question was closed Jan 10, 2013 at 10:20 AM by Fattie for the following reason:

Problem is not reproducible or outdated, closed it himself

avatar image
0
Question by stagg250 · Jan 07, 2013 at 04:01 PM · playerenemypush

Making enemy push player

Hi guys!

I have this code 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;
 
 
 }

The "enemy" only circle around player, so what I want is the enemy pushes player so he can fall off.

Thanks is advance!!

Comment
Add comment · Show 6
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 AlucardJay · Jan 07, 2013 at 04:15 PM 1
Share

Are the NPCs fully rotating to face the player? Try using Lerp ins$$anonymous$$d of Slerp, and/or increase the rotationSpeed.

avatar image stagg250 · Jan 07, 2013 at 04:49 PM 0
Share

I tried Lerp, but nothing happened.

To be more specific, I have a sphere which represents enemy, and sphere is moving towards Player. When sphere come closer, it just circle around my Player character, and doesn't push me at all.

avatar image AlucardJay · Jan 07, 2013 at 05:00 PM 1
Share

Does your player and your enemy both have rigidbody components attached?

Edit : If you are using a character controller, you may want to look at the physics character controllers :

http://wiki.unity3d.com/index.php/PhysicsFPSWalker

http://wiki.unity3d.com/index.php/RigidbodyFPSWalker

from : http://wiki.unity3d.com/index.php/Scripts/Controllers

avatar image stagg250 · Jan 07, 2013 at 05:14 PM 0
Share

Yes, both Player and Enemy have RigidBody attached.

But I'm trying to enemy push Player, which have default FPS script attached, in your case it was just an Sphere with no movement scripts in it.

Found this in Documentation:

The Controller does not react to forces on its own and it does not automatically push Rigidbodies away.

If you want to push Rigidbodies or objects with the Character Controller, you can apply forces to any object that it collides with via the OnControllerColliderHit() function through scripting.

On the other hand, if you want your player character to be affected by physics then you might be better off using a Rigidbody ins$$anonymous$$d of the Character Controller.

$$anonymous$$aybe you guys can help me now... I'm new in Unity.

Thanks for your time. :)

avatar image stagg250 · Jan 08, 2013 at 12:36 AM 0
Share

Can you guys please help me with this? I really need enemy to push Character off the platform, otherwise it's useless.

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Enemies push player a ridiculous amount. 1 Answer

Distance destroy object 3 Answers

How come my Player, Enemy, Animation & HealthSlider won't correspond to one another? 1 Answer

Player wont take damage 2 Answers

Damage script is screwed up...? what to do? 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