Hey guys!
I am doing a random game and would like to add a fun feature… Click-Push! I am learning C++ and Java Script but I can’t figure out how to do this… If somebody could help me, that would be great! I would like it to use a Ray that goes out like 2 feet, and when you click… It applies force to what ever is in its way. If the force and range could be changed in the Inspector that would be great, but if I have to go into the script, that would be fine too!
Thanks guys for all your help! I understand that asking for a script is not “smiled upon” on Unity Forums, but other people could use this, so I thought it would be worth asking… Also it, most likely, is not a hard/ long script to write, so it wont take much of your time…
-Thanks Guys; Gibson
Hey, I’m an occasional forum lurker that is trying to figure out how to program.
Here is what I’ve got so far for you problem. It doesn’t work, but with a bit of messing I’m fairly certain it will. It’s just late, and I’m laaaazy.
var range = 5.0;
var force = 10.0;
var buttondown : boolean = false;
//add whatever trigger system you like, this is mine >.>;;
function Start()
{
Trigger();
}
function Trigger()
{
while(!buttondown)
{
if(Input.GetKeyDown(2))
{
buttondown = true;
Debug.Log("buttonhit");
//this is the important bit
var playerdirection = transform.TransformDirection (Vector3.forward);
var hit : RaycastHit;
Physics.Raycast (transform.position, playerdirection, hit, range);
if (hit.rigidbody)
{
hit.rigidbody.AddForceAtPosition(force * playerdirection, hit.point);
}
}
}
}
I used the fps tutorial frame work for the raycast / force application because I don’t quite understand the syntax for raycast and the force yet.
here is a link to the fps tutorial http://unity3d.com/support/resources/tutorials/fpstutorial
and one for the scripting refrence which has all this stuff file:///C:/Program%20Files/Unity/Editor/Data/Documentation/Documentation/ScriptReference/index.html
Hope this helped, good luck!