February 04, 2012, 03:30:30 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Rotating an object when I press a key  (Read 1564 times)
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« on: March 20, 2010, 04:33:12 PM »

I'm in the process of making a robot vehicle with a mechanical arm. It's driving around OK. All I want to do really is be able to move the arm around. How do I rotate the different components when I press a key?

It should be quite simple, press A to rotate left, press D to rotate right etc.
I've tried copying the method used by the car wheels but I can't get it to work.


« Last Edit: March 20, 2010, 04:36:07 PM by BigDaz » Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #1 on: March 20, 2010, 05:23:27 PM »

Robot 01
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #2 on: March 22, 2010, 02:32:44 PM »

Is the arm a separate mesh?  If so, use...
Code:
object.GetMesh("YourMeshName").SetRotationEuler( vector);
For the vector, you probably want to grab the current rotation - object.GetMesh( mesh).GetRotationEuler() - and then for every step in which the key is pressed, add one or so to the Axis you're pivoting on.

I know that you know how to handle the key press part.
Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #3 on: March 23, 2010, 05:19:17 AM »

Yes each component to be moved is a separate mesh. Does moving the mesh rotate a collision object so it can interact with other objects? I have a fairly good idea of inputs from the sticky thread although I'd like an example of how this would be done.
« Last Edit: March 25, 2010, 11:29:00 AM by BigDaz » Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #4 on: March 25, 2010, 11:29:42 AM »

Ready for deployment Cool

Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #5 on: March 25, 2010, 12:17:09 PM »

that is some cool stuff you have there Smiley
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #6 on: March 29, 2010, 01:09:19 PM »

Here's a simple example of how to rotate an object's mesh when you press a key...

First, in the opr (see the comments for details)...

Code:
LoadObject robot.3ds
ObjectName robot

ControllerType Scripted
ControllerSetting ScriptFile robot.gsl

CastShadow 1
ReceiveShadows 1
VisibleInReflections 0
EnableLightMap 0
CastLightMapShadow 0

ClearRoadConnectors 1

LoadObject robotArm.3ds // load the second object
ObjectName arm1 // give it a name so we can create a handle to it in our script
ObjectParent robot // declare the main mesh the parent
ObjectPosition 0.0000 1.0000 0.5000 // adjust the position, if necessary


Then in the gsl (again, see the comments and also note that I've stripped all but the relative commands out of this script)...

Code:

//At the top, in the constants / variables section...

ObjectMesh@ arm1; // this is going to be the handle to our mesh

Vector arm1Rot; // this will be used for the mesh's rotation

float firePressed = 0;  /*// this will be used to determine if the LMB is pressed (note, this is probably already declared if you're modifying an existing GC player script) */

//In the initialize section...
void Initialize( Object@ object)
{

@arm1 = object.GetMesh( "arm1"); // create the actual handle to the mesh

}


// In the Handle Event section...
//"Fire" must be mapped in Input.cfg (probably already is)
bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
{


if (event == "Input")
{
if (params.stringValue == "Fire")
{
firePressed = params.floatValue; // set the float firePressed to equal the value of the input
return true;
}
return false;
}
return false;
}

// In the dynamic events section...
void DynamicsAdvance( Object@ object, float seconds)
{

if(firePressed > 0.5)
{
arm1Rot = arm1.GetRotationEuler(); // set our variable to equal the current rotation of the mesh
arm1.SetRotationEuler(Vector(arm1Rot.x, arm1Rot.y + 1, arm1Rot.z)); // set the rotation of the mesh

}
}

Again, that's a really simple example, but that should get you started in the right direction.  You could easily setup a second button to have it rotate in the opposite direction as well.
Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #7 on: March 29, 2010, 05:27:03 PM »

Perfect, just what I needed. Thanks a lot.
Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #8 on: March 30, 2010, 05:58:20 PM »

Well it all works great but doesn't collide with anything as it stands.
Is it possible to add collision objects to each part and have it rotate along with the mesh?
Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #9 on: April 02, 2010, 05:09:03 PM »

Is it possible to move one part of an object with collision? I can't find any examples.
Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #10 on: April 03, 2010, 11:10:23 AM »

Robot 03
Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #11 on: April 04, 2010, 08:37:20 AM »

One minor problem I noticed with the vehicle template is that the camera target is global instead of being localised to the vehicles rotation.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #12 on: April 06, 2010, 03:17:27 PM »

daz, that is really cool!
Logged
BigDaz
Sr. Member
****
Posts: 345


HardCore


View Profile
« Reply #13 on: May 05, 2010, 04:17:10 AM »

Is it possible to move one part of an object with collision? I can't find any examples.

I assume this isn't possible then.
Logged
ross.rockafellow
Global Moderator
Full Member
*****
Posts: 142



View Profile
« Reply #14 on: May 05, 2010, 10:25:18 AM »

You should be able to yes. You might have to use separate collision meshes for each moving part though. I'm going to run some tests today and see if I can't get that bit working. I've been wanting to build a claw machine anyways =) I'm going to lift your code from here and see if I can get anything working.

I'll post back as soon as I have something =)
Logged
Pages: [1] 2
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!