Multiboxing.com - Multiboxing in World of Warcraft and more!
          

Go Back   Multiboxing in World of Warcraft and Beyond! > All Gaming Forums > Off Topic

Reply
 
LinkBack Thread Tools Display Modes
Old 01-22-2012, 03:49 PM   #1
Senior Member
 
supamario00's Avatar
 
Join Date: Jan 2010
Location: Missoura
Posts: 323
Default Javascript Problem

I can't seem to figure out a script that would allow me to, using the scroll wheel, move a rigidbody back and forth through its relative z axis (3D project so x,y,z).

The way it's set up in Unity is that you hold the left mouse button to pick up the item and it will move with you, what I need to do is to be able to push the rigidbody back and forth using the scroll wheel.

If anyone can figure this out I would be super appreciative as this has been confusing me for the last week.
__________________

MY LOCKS BEAT YOUR LOCKS
supamario00 is offline   Reply With Quote
Old 01-22-2012, 04:28 PM   #2
Super Moderator
 
Nghtmr9999's Avatar
 
Join Date: Aug 2009
Location: Minnesota, US
Posts: 1,662
Blog Entries: 6
Default Re: Javascript Problem

We need some code to help you out, silly
__________________
Nghtmr9999 is offline   Reply With Quote
Old 01-22-2012, 04:33 PM   #3
Senior Member
 
supamario00's Avatar
 
Join Date: Jan 2010
Location: Missoura
Posts: 323
Default Re: Javascript Problem

post the whole drag rigidbody script?
__________________

MY LOCKS BEAT YOUR LOCKS
supamario00 is offline   Reply With Quote
Old 01-22-2012, 04:35 PM   #4
Senior Member
 
supamario00's Avatar
 
Join Date: Jan 2010
Location: Missoura
Posts: 323
Default Re: Javascript Problem

var spring = 50.0;
var damper = 5.0;
var drag = 10.0;
var angularDrag = 5.0;
var distance = 0.2;
var attachToCenterOfMass = false;

private var springJoint : SpringJoint;

function Update ()
{
// Make sure the user pressed the mouse down
if (!Input.GetMouseButtonDown (0))
return;

var mainCamera = FindCamera();

// We need to actually hit an object
var hit : RaycastHit;
if (!Physics.Raycast(mainCamera.ScreenPointToRay(Inpu t.mousePosition), hit, 100))
return;
// We need to hit a rigidbody that is not kinematic
if (!hit.rigidbody || hit.rigidbody.isKinematic)
return;

if (!springJoint)
{
var go = new GameObject("Rigidbody dragger");
var body : Rigidbody = go.AddComponent ("Rigidbody") as Rigidbody;
springJoint = go.AddComponent ("SpringJoint");
body.isKinematic = true;
}

springJoint.transform.position = hit.point;
if (attachToCenterOfMass)
{
var anchor = transform.TransformDirection(hit.rigidbody.centerO fMass) + hit.rigidbody.transform.position;
anchor = springJoint.transform.InverseTransformPoint(anchor );
springJoint.anchor = anchor;
}

else
{
springJoint.anchor = Vector3.zero;
}


springJoint.spring = spring;
springJoint.damper = damper;
springJoint.maxDistance = distance;
springJoint.connectedBody = hit.rigidbody;

StartCoroutine ("DragObject", hit.distance);
}

function DragObject (distance : float)
{
var oldDrag = springJoint.connectedBody.drag;
var oldAngularDrag = springJoint.connectedBody.angularDrag;
springJoint.connectedBody.drag = drag;
springJoint.connectedBody.angularDrag = angularDrag;
var mainCamera = FindCamera();
while (Input.GetMouseButton (0))
{
var ray = mainCamera.ScreenPointToRay (Input.mousePosition);
springJoint.transform.position = ray.GetPoint(distance);
yield;
}
if (springJoint.connectedBody)
{
springJoint.connectedBody.drag = oldDrag;
springJoint.connectedBody.angularDrag = oldAngularDrag;
springJoint.connectedBody = null;
}

}

function FindCamera ()
{
if (camera)
return camera;
else
return Camera.main;
}
__________________

MY LOCKS BEAT YOUR LOCKS
supamario00 is offline   Reply With Quote
Old 01-23-2012, 05:56 AM   #5
Super Moderator
 
Join Date: Jul 2009
Posts: 413
Default Re: Javascript Problem

have a look at this, this looks promising:
Mouse wheel programming in JavaScript
Chamassa is offline   Reply With Quote
Old 01-23-2012, 01:13 PM   #6
Senior Member
 
supamario00's Avatar
 
Join Date: Jan 2010
Location: Missoura
Posts: 323
Default Re: Javascript Problem

Quote:
Originally Posted by Chamassa View Post
have a look at this, this looks promising:
Mouse wheel programming in JavaScript
the only problem is that that is the name for mouse wheel in browser but I need it for a non browser program

what I was using was Input.GetAxis ("Mouse Scrollwheel") because that is what it is defined as in unity but I can't figure out how to get it to translate a picked up rigidbody along it's z axis
__________________

MY LOCKS BEAT YOUR LOCKS
supamario00 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with app Hengist Multiboxing Software 10 05-11-2011 06:00 PM
Bad ProbleM genesis Multiboxing Guides 3 11-11-2010 12:44 PM
WTB Javascript programmer Nghtmr9999 Off Topic 3 06-16-2010 09:42 PM
New PC Problem Paul1337noob Multiboxing Computer Hardware 8 02-28-2010 07:00 PM
anyone else having this problem? cheesybacon22 General Discussions 4 10-18-2009 03:20 PM


SEO by vBSEO 3.3.2