Ninjor Posted July 10, 2010 Share Posted July 10, 2010 I'm writing a script that will cause an object to be created and move based on the player cars speed. I want the object to have collision, but it goes through walls. Here's what I've written: thread "Rico":Rico_1wait 00247: load_model 1574 wait 0IF AND0248: model 1574 available0AB0: key_pressed 103 004D: jump_if_false @Rico_1 04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 20.0 0.00107: [email protected] = create_object 1574 at [email protected] [email protected] [email protected]: set_object [email protected] mass_to 300.0 // float0908: set_object [email protected] turn_mass_to 300 0392: object [email protected] toggle_in_moving_list 103C0: [email protected] = actor $PLAYER_ACTOR carObject.CollisionDetection([email protected]) = True06A2: get_car [email protected] velocity_in_direction_XYZ [email protected] [email protected] [email protected]: set_object [email protected] rotation_velocity_about_an_axis 1.0 0.0 0.0 through_center_of_body0381: throw_object [email protected] velocity_in_direction [email protected] [email protected] [email protected] @Rico_1 Link to comment Share on other sites More sharing options...
ZAZ Posted July 10, 2010 Share Posted July 10, 2010 (edited) I'm writing a script that will cause an object to be created and move based on the player cars speed. I want the object to have collision, but it goes through walls. Here's what I've written: At first, you're using opcode 0AB0:, so you have cleo installed but to make a cleo script you must add the cleo directive: {$CLEO .cs} But for now I'm assuming that it should be a thread of main.scm The objects have different behavior depending to their settings in object.dat Try the script below to see a working object when it was thrown. It use the 3054, DYN_WREKING_BALL. Then change the DYN_WREKING_BALL with your object and try again. //{$CLEO .cs}//--everything behind two slashes will be ignored by compiling:Objectthrow_003A4: name_thread 'OTHROW':Objectthrow_10001: wait 0 ms00D6: if 00256: player $PLAYER_CHAR defined004D: jump_if_false @Objectthrow_1if0AB0: key_pressed 8//-----------------------------press backspace 004D: jump_if_false @Objectthrow_10247: request_model 3054:Objectthrow_30001: wait 0 ms00D6: if 00248: model 3054 available004D: jump_if_false @Objectthrow_304C4: create_coordinate [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR offset 0.0 5.0 0.00107: [email protected] = create_object 3054 at [email protected] [email protected] [email protected]: set_object [email protected] mass_to 300.0 // float0908: set_object [email protected] turn_mass_to 30004D9: object [email protected] set_scripted_collision_check 10382: set_object [email protected] collision_detection 1wait 20000392: object [email protected] toggle_in_moving_list 10381: throw_object [email protected] distance 0.0 5.0 15.0wait 5000Object.Destroy([email protected])0249: release_model 30540002: jump @Objectthrow_1 Edited July 10, 2010 by ZAZ CLEO MODS CLEO Script Tutorial Link to comment Share on other sites More sharing options...
Ninjor Posted July 10, 2010 Author Share Posted July 10, 2010 Thanks for the help, by adding some code I was able to launch an object in front of the player. Now I would like to make it so the object keeps moving at a constant speed rather than fall to the ground, if anyone knows a way to do this I would be grateful. Here's the code I'm using: {$VERSION 3.1.0027}{$CLEO .cs}//-------------MAIN---------------thread 'OTHROW' :OTHROW_11wait 0 if Player.Defined($PLAYER_CHAR)else_jump @OTHROW_11 if 0AB0: key_pressed 103 else_jump @OTHROW_11 Model.Load(3065):OTHROW_51wait 0 if Model.Available(3065)else_jump @OTHROW_51 04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 5.0 0.0 [email protected] = Object.Create(3065, [email protected], [email protected], [email protected])Object.CollisionDetection([email protected]) = TrueObject.ToggleInMovingList([email protected]) = Truewait 0 [email protected] = Actor.Angle($PLAYER_ACTOR)[email protected] = 80.10819: [email protected] = actor $PLAYER_ACTOR distance_from_ground02F6: [email protected] = sine [email protected] // (float) 02F7: [email protected] = cosine [email protected] // (float) 006B: [email protected] *= [email protected] // (float) 006B: [email protected] *= [email protected] // (float) [email protected] *= -1.0 [email protected] += 1.0 0381: throw_object [email protected] velocity_in_direction [email protected] [email protected] [email protected] 0Model.Destroy(3065)jump @OTHROW_11 Some of it was taken from the knife throwing mod. Link to comment Share on other sites More sharing options...
Adler Posted July 10, 2010 Share Posted July 10, 2010 (edited) Attach it to a car (which you should make invisible) and do Car.SetSpeedInstantly. EDIT - The car should also be facing in the direction you want the object to go using 07C6. I don't know how that opcode works exactly though. Edited July 11, 2010 by Adler Link to comment Share on other sites More sharing options...
ZAZ Posted July 11, 2010 Share Posted July 11, 2010 (edited) Attach it to a car (which you should make invisible) and do Car.SetSpeedInstantly. EDIT - The car should also be facing in the direction you want the object to go using 07C6. I don't know how that opcode works exactly though. using a car as helper? don't know if that will be the best method Thanks for the help, by adding some code I was able to launch an object in front of the player. Now I would like to makes it so the object keeps moving at a constant speed rather than fall to the ground, if anyone knows a way to do this I would be grateful. Here's the code I'm using: {$VERSION 3.1.0027}{$CLEO .cs}//-------------MAIN---------------thread 'OTHROW' :OTHROW_11wait 0 if Player.Defined($PLAYER_CHAR)else_jump @OTHROW_11 if 0AB0: key_pressed 103 else_jump @OTHROW_11 Model.Load(3065):OTHROW_51wait 0 if Model.Available(3065)else_jump @OTHROW_51 04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 5.0 0.0 [email protected] = Object.Create(3065, [email protected], [email protected], [email protected])Object.CollisionDetection([email protected]) = TrueObject.ToggleInMovingList([email protected]) = Truewait 0 [email protected] = Actor.Angle($PLAYER_ACTOR)[email protected] = 80.10819: [email protected] = actor $PLAYER_ACTOR distance_from_ground02F6: [email protected] = sine [email protected] // (float) 02F7: [email protected] = cosine [email protected] // (float) 006B: [email protected] *= [email protected] // (float) 006B: [email protected] *= [email protected] // (float) [email protected] *= -1.0 [email protected] += 1.0 0381: throw_object [email protected] velocity_in_direction [email protected] [email protected] [email protected] 0Model.Destroy(3065)jump @OTHROW_11 Some of it was taken from the knife throwing mod. You found now the bball which have the best behavior for throwing and collision. To give it more power for bumping cars needs to increase the mass and the multiplier 0906: set_object [email protected] mass_to 30000.0 // float It have then also a gravity behavior in the gameworld and make a ballistic curve by throwing. We can stretch the curve by adjusting the multiplier for the x/y parameter and the height parameter [email protected] = 250.1//-- multiplier 0381: throw_object [email protected] velocity_in_direction [email protected] [email protected] 5.0 In addition do you need to destroy the object after using or remove it's reference. You may not spawn unlimited items without discharging from script Model.Destroy(3065) release only the loaded file but not the object instance You must use 0108: destroy_object [email protected] or 01C4: remove_references_to_object [email protected] but set a wait of a few seconds before destroying otherwise the object won't do it's effect {$CLEO .cs}//-------------MAIN---------------thread 'OTHROW':OTHROW_11wait 0if Player.Defined($PLAYER_CHAR)else_jump @OTHROW_11if0AB0: key_pressed 103// numeric keypad 7 keyelse_jump @OTHROW_11Model.Load(3065):OTHROW_51wait 0if Model.Available(3065)else_jump @OTHROW_5104C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 2.0 [email protected] = Object.Create(3065, [email protected], [email protected], [email protected])0906: set_object [email protected] mass_to 30000.0 // float Object.CollisionDetection([email protected]) = TrueObject.ToggleInMovingList([email protected]) = Truewait [email protected] = Actor.Angle($PLAYER_ACTOR)[email protected] = 250.10819: [email protected] = actor $PLAYER_ACTOR distance_from_ground02F6: [email protected] = sine [email protected] // (float)02F7: [email protected] = cosine [email protected] // (float)006B: [email protected] *= [email protected] // (float)006B: [email protected] *= [email protected] // (float)[email protected] *= [email protected] += 1.00381: throw_object [email protected] velocity_in_direction [email protected] [email protected] 5.0wait 3000Model.Destroy(3065)0108: destroy_object [email protected] @OTHROW_11 Now, if you wonna do it in vehicle you must consider that the spawned object infront of the car can bump the own player_car especially because the vehicle can have high speed So get the model dimensions of the vehicle and add some units Now you can also use 06A2: get_car [email protected] velocity to use the values for the object throwing but it will be slow especially when the vehicle is standing so add some floats and multiplicate it with some floats I think the calculation with sin and cosin is the better solution {$CLEO .cs}//-------------MAIN---------------thread 'CAROBJT':CAROBJT_11wait 0if Player.Defined($PLAYER_CHAR)else_jump @CAROBJT_11if and00DF: actor $PLAYER_ACTOR driving0AB0: key_pressed 103// numeric keypad 7 keyelse_jump @CAROBJT_1103C0: [email protected] = actor $PLAYER_ACTOR car0441: [email protected] = car [email protected] model07E4: get_model [email protected] dimensions_cornerA_to [email protected] [email protected] [email protected] dimensions_cornerB_to [email protected] [email protected] [email protected]@ += 5.0jump @CAROBJT_17:CAROBJT_15wait 0if Player.Defined($PLAYER_CHAR)else_jump @CAROBJT_75if and00DF: actor $PLAYER_ACTOR driving8119: not car [email protected] wrecked else_jump @CAROBJT_75if0AB0: key_pressed 103// numeric keypad 7 keyelse_jump @CAROBJT_15:CAROBJT_17Model.Load(3065):CAROBJT_25wait 0if Model.Available(3065)else_jump @CAROBJT_250407: create_coordinate [email protected] [email protected] [email protected] from_car [email protected] offset 0.0 [email protected] [email protected] = Object.Create(3065, [email protected], [email protected], [email protected])0906: [email protected] 30000.0//set_object massObject.CollisionDetection([email protected]) = TrueObject.ToggleInMovingList([email protected]) = Truewait 0//jump @CAROBJT_3006A2: get_car [email protected] velocity_in_direction_XYZ [email protected] [email protected] [email protected]@ += [email protected] += [email protected] *= [email protected] *= 10.0{:CAROBJT_300174: [email protected] = car [email protected] [email protected] = 250.102F6: [email protected] = sine [email protected] // (float)02F7: [email protected] = cosine [email protected] // (float)006B: [email protected] *= [email protected] // (float)006B: [email protected] *= [email protected] // (float)[email protected] *= -1.0}0381: throw_object [email protected] velocity_in_direction [email protected] [email protected] 5.0wait 3000Model.Destroy(3065)0108: destroy_object [email protected] @CAROBJT_15:CAROBJT_7501C3: remove_references_to_car [email protected] @CAROBJT_11 Remove the comments and change the local vars in opcode 0381: to change the throw calculation with the sin/cosin method 0407: create_coordinate [email protected] [email protected] [email protected] from_car [email protected] offset 0.0 [email protected] [email protected] = Object.Create(3065, [email protected], [email protected], [email protected])0906: [email protected] 30000.0//set_object massObject.CollisionDetection([email protected]) = TrueObject.ToggleInMovingList([email protected]) = Truewait 0jump @CAROBJT_3006A2: get_car [email protected] velocity_in_direction_XYZ [email protected] [email protected] [email protected]@ += [email protected] += [email protected] *= [email protected] *= 10.0:CAROBJT_300174: [email protected] = car [email protected] [email protected] = 250.102F6: [email protected] = sine [email protected] // (float)02F7: [email protected] = cosine [email protected] // (float)006B: [email protected] *= [email protected] // (float)006B: [email protected] *= [email protected] // (float)[email protected] *= -1.00381: throw_object [email protected] velocity_in_direction [email protected] [email protected] 5.0wait 3000Model.Destroy(3065)0108: destroy_object [email protected] @CAROBJT_15 Edited July 11, 2010 by ZAZ CLEO MODS CLEO Script Tutorial Link to comment Share on other sites More sharing options...
Ninjor Posted July 11, 2010 Author Share Posted July 11, 2010 Thank you ZAZ it works great, but there is one last thing that I don't know how to do. I need the object to stay on the ground, but still be moving, and be able to go over hills and ramps without launching into the air. Link to comment Share on other sites More sharing options...
ZAZ Posted July 11, 2010 Share Posted July 11, 2010 Thank you ZAZ it works great, but there is one last thing that I don't know how to do. I need the object to stay on the ground, but still be moving, and be able to go over hills and ramps without launching into the air. you wonna make a cruise missile, that's very difficult CLEO MODS CLEO Script Tutorial Link to comment Share on other sites More sharing options...
Ninjor Posted July 11, 2010 Author Share Posted July 11, 2010 If it's too much for you to do then I'm okay with that, but could you point me in the right direction? Link to comment Share on other sites More sharing options...
Deji Posted July 12, 2010 Share Posted July 12, 2010 I think there's a function for getting the Y angle of any point, but I'm unable to find it at the moment Maybe this does the same? 0604: get_Z_angle_for_point [email protected] [email protected] store_to [email protected] ] Seems odd that it would get the Z angle for a point, maybe it's misnamed. Use it and set the objects Y angle to the result. Link to comment Share on other sites More sharing options...
Ninjor Posted July 12, 2010 Author Share Posted July 12, 2010 (edited) Thank you for the help, though I have a problem. I don't know how to set the Y angle, because I can't find an opcode to do it. EDIT: Nevermind, I misunderstood. Edited July 12, 2010 by Ninjor Link to comment Share on other sites More sharing options...
ZAZ Posted July 12, 2010 Share Posted July 12, 2010 I think there's a function for getting the Y angle of any point, but I'm unable to find it at the moment Maybe this does the same? 0604: get_Z_angle_for_point [email protected] [email protected] store_to [email protected] ] Seems odd that it would get the Z angle for a point, maybe it's misnamed. Use it and set the objects Y angle to the result. we talked about 0604: half year ago: Unsine and Uncosine Today I found 080A: get_object [email protected] spoot 2 store_to [email protected] [email protected] [email protected] and I'm wondedring what it means I don't know the word spoot maybe it means spin? If it's too much for you to do then I'm okay with that, but could you point me in the right direction? I see only one chance, check the distance to ground and throw the object again 01BB: store_object [email protected] position_to [email protected] [email protected] [email protected]: [email protected] = ground_z_at [email protected] [email protected] [email protected]: [email protected] -= [email protected] // (float)if0023: 1.5 > [email protected]: jump_if_false @CAROBJT_47 0381: throw_object [email protected] velocity_in_direction [email protected] [email protected] 5.0 well, i think you don't want that the object flys endless so you will need a condition to find an end normaly you would check if it collides but then it will collide before the script can react because of low distance to ground because it's to fast CLEO MODS CLEO Script Tutorial Link to comment Share on other sites More sharing options...
Deji Posted July 12, 2010 Share Posted July 12, 2010 Oh yes, I remember the use for the opcode now. In fact I've been using it loads, but the context of what I was looking for confused me. If that opcode hadn't already been named to that for so long, I'd rename it "asin" or something I think spoot is something to do with the corners of an object, or more precisely, it's corners and edges as a cube... Spoot isn't really the most useful word for it. It's not even googlable. Still, unless I can find the Ground Y Angle Function, I doubt there's any easy way of going about this. I'm really surprised I couldn't find it when searching Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now