- Home /
C# Star wars force script
Ok first: When I say force, I don't mean adding force to a rigid body with script, I mean like a star wars force-like script: Where you can push enemies/objects back by hitting a key. Im working on a project that requires it. I was thinking I would do this with a raycast or something, but I am not very good with raycast. While I'm not the best with scripting, I am a lot more flexible with C#, so if you can help me with a script written in C#, that would be very much appreciated! I appreciate any help! Thank you so much in advance!
Nikolai
UA is not the place to ask for Scripts to be written for you. If you have a specific question or are stuck on something specific while you are writing a script yourself, then we can help you.
Although I agree with them that this is not the correct place for your answer, I think I know how this could be done (Besides what FireDan said). But I want to know, what are you doing besides AddForce? You said you don't want it, but how else will it move? Translating? Position Altering?
I'd love to help, this seems like a fun challenge for me, but I need more information about the end product for which you're looking.
Noah.
Answer by Firedan1176 · Mar 08, 2014 at 05:39 AM
mattyman is correct, but I believe I can help in your situation. If you aren't the best at raycast, I suggest going with a sort of cone shape coming out of the main camera. Set the renderer to disabled (make sure this cone is attached to the camera as a child). Then place a script on the cone and use "Void OnTriggerEnter(Collider other)" to do your movements. The only problem is with this is how are you going to decide if you're pushing or pulling? You can use either changing the transform directly or some tinkering with the rigidbody. Also make sure your "cone" is set to isTrigger. If you don't know what I'm going for, whatever the cone is touching is whatever you can move. Only problem is clipping through walls and moving things like that...
Your answer
![](https://koobas.hobune.stream/wayback/20220613135656im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Error when using getComponent to use a variable 1 Answer
C# how to have a part of an object rotate while animation is being played 2 Answers
C# scriping help 0 Answers
SetActive() Object reference not set to an instance of an object. 1 Answer