Designing a simple motion script [with video]

Users who are viewing this thread

_Sebastian_ said:
randomcode said:
Why can't I rotate turret? Help!
...cause you did something wrong.
Short question, short answer.
I copy the code from the topic and just add some code that let tanks play sound when moving:
Code:
common_tank_init_1=(
	ti_before_mission_start, 0, ti_once, 
	[], 
	[
			(set_spawn_radius, 0), # make array for groups
			(spawn_around_party, 1, "pt_none"),
			(assign, "$dyn_groups", reg0),
			(try_for_range,":array_index",0,scene_prop_group_limit), # initialize array
				(party_set_slot,"$dyn_groups",":array_index",-1),
			(try_end),
			(assign, "$elemate", 0),
			(assign,"$spawned",0),
	]
)

common_tank_init_2=(
	0, 0, 0, 
	[],
	[
		(assign, ":end", scene_prop_group_limit),
		(try_for_range,":array_index",0,":end"), # try for all groups
			(assign, reg0, ":array_index"),
			#(display_debug_message, "@{reg0}"),
			(party_get_slot,":group","$dyn_groups",":array_index"),
			(try_begin),
				(eq, ":group", -1),
				(assign, ":end", ":array_index"),	
			(try_end),
			(neg|eq, ":group", -1),
			(assign, ":sub_end", 30),
			(try_for_range,":sub_array_index",0,":sub_end"), # try for group members		
				(party_get_slot,":instance",":group",":sub_array_index"),
				(try_begin),
					(eq, ":instance", -1),
					(assign, ":end", ":sub_array_index"),	
				(try_end),	
				(neg|eq, ":instance", -1),
				(scene_prop_get_slot,":enable",":instance",scene_prop_enable_jl_dynamics),
				(scene_prop_get_slot,":parent",":instance",scene_prop_parent),
				(ge, ":enable", 1),
				###########################################
				# Parent conditions that change abs value #
				###########################################
				(try_begin), #parent only conditions
					(eq, ":parent", -1),
					#(display_debug_message, "@is parent(abs)"),
					(try_begin), #try involving abs positions
						(scene_prop_get_slot,":vel_abs_z",":instance",scene_prop_vel_abs_z),	
						(scene_prop_get_slot,":enable",":instance",scene_prop_set_z_ground),
						(eq, ":enable", 0),
						(call_script, "script_store_scene_prop_abs_pos_to_pos0", ":instance"),
						(position_get_distance_to_ground_level, ":distance", pos0),
						(store_mul,":neg_vel_abs_z",-1,":vel_abs_z"),
						(try_begin),
							(ge, ":neg_vel_abs_z", ":distance"), ##### NEED FIX ########
							(position_set_z_to_ground_level, pos0),
							(position_get_z, ":z", pos0),
							(call_script, "script_set_scene_prop_group_abs_z", ":instance", ":z"),				
						(else_try),
							(call_script, "script_move_scene_prop_group_abs_z", ":instance", ":vel_abs_z"),	
						(try_end),
					(end_try),
					(try_begin), 
						(scene_prop_get_slot,":vel_abs_y",":instance",scene_prop_vel_abs_y),	
						(call_script, "script_move_scene_prop_group_abs_y", ":instance", ":vel_abs_y"),						
					(end_try),
					(try_begin),
						(scene_prop_get_slot,":gravity",":instance",scene_prop_gravity), #### Needs to be MOVED ####
						(neg|eq, ":gravity", 0),		
						(scene_prop_get_slot,":vel_abs_z",":instance",scene_prop_vel_abs_z),
						(val_sub, ":vel_abs_z", ":gravity"),
						(scene_prop_set_slot,":instance",scene_prop_vel_abs_z,":vel_abs_z"),						
					(end_try),
					(try_begin), 
						(scene_prop_get_slot,":value",":instance",scene_prop_set_z_ground),
						(ge, ":value", 1),
						(call_script, "script_store_scene_prop_abs_pos_to_pos0", ":instance"),	
						#(position_set_z, pos0, 10000),
						(position_get_distance_to_terrain, ":distance", pos0),
						(val_mul, ":distance", -1),
						(val_sub, ":value", 1),
						(val_add, ":distance", ":value"),
						(call_script, "script_move_scene_prop_group_abs_z", ":instance", ":distance"),
					(end_try),#try involving abs positions
				(end_try), #parent only conditions
				###########################################
				# Conditions that change other properties #
				###########################################		
				(try_begin), # Rotation
					(scene_prop_get_slot,":omega_x",":instance",scene_prop_rel_ome_x), 	
					(scene_prop_get_slot,":rel_rot_x",":instance",scene_prop_rel_rot_x),
					(val_add, ":rel_rot_x", ":omega_x"),
					(scene_prop_set_slot,":instance",scene_prop_rel_rot_x,":rel_rot_x"),						
				(end_try), # Rotation		 		
				(try_begin), # Wheel Rotation Speed determination
					(scene_prop_get_slot,":is_wheel",":instance",scene_prop_is_wheel),
					(eq, ":is_wheel", 1),
					(call_script, "script_scene_prop_get_master", ":instance"),
					(assign, ":master", reg0),
					(scene_prop_get_slot,":parent_v_y",":master",scene_prop_vel_abs_y),
					(scene_prop_get_slot,":radius_pi",":instance",scene_prop_radius),
					(val_mul, ":radius_pi", PI),
					(store_div, ":omega", 20000, ":radius_pi"),
					(val_mul, ":omega", ":parent_v_y"),
					(val_mul, ":omega", -1),
					(scene_prop_set_slot,":instance",scene_prop_rel_ome_x,":omega"),
				(end_try), # Wheel Rotation 
				################
				# START RENDER #
				################
				# pos30 is final position #
				(call_script, "script_store_scene_prop_abs_pos_to_pos0", ":instance"),
				(copy_position, pos30, pos0),
				################################
				# Step 1: Render Slopes etc... #
				################################
				(try_begin), # parent-only renders
					(eq, ":parent", -1),
					#(display_debug_message, "@is parent(slope)"),
					(try_begin), 
						(scene_prop_get_slot,":slope_trigger",":instance",scene_prop_follow_slope),
						(ge, ":slope_trigger", 1),
						(scene_prop_get_slot,":length",":instance",scene_prop_length),
						(call_script, "script_get_slope_y_pos0", ":length"),
						(assign, ":slope_y", reg0),
						(position_rotate_x, pos30, ":slope_y"),			
						(try_begin),	
							(ge, ":slope_trigger", 2),
							(scene_prop_get_slot,":width",":instance",scene_prop_width),
							(call_script, "script_get_slope_x_pos0", ":width"),
							(assign, ":slope_x", reg0),
							(position_rotate_y, pos30, ":slope_x"),		
						(try_end),
					(try_end),
				(try_end), # parent-only renders
				################################
				# Step 2: Copy Parent's render #
				################################
				(try_begin), # child-only 
					(neg|eq, ":parent", -1),	
					(call_script, "script_store_scene_prop_abs_pos_to_pos0", ":parent"),
					(copy_position, pos1, pos0), # pos 1: parent abs pos
					(call_script, "script_store_scene_prop_abs_pos_to_pos0", ":instance"),
					(copy_position, pos2, pos0), # pos2: child abs pos		
					(position_transform_position_to_local, pos3, pos1, pos2), # pos 3: child in terms of parent
					(prop_instance_get_position, pos4, ":parent"), # pos4: parent rendered pos
					(position_transform_position_to_parent, pos30, pos4, pos3), #pos30: final							
				(try_end), # child-only				
				######################################
				# Step 3: Add oneself's rel. renders #
				######################################
				(scene_prop_get_slot,":rel_x",":instance",scene_prop_rel_pos_x),
				(scene_prop_get_slot,":rel_y",":instance",scene_prop_rel_pos_y),
				(scene_prop_get_slot,":rel_z",":instance",scene_prop_rel_pos_z),
				(scene_prop_get_slot,":rel_rot_x",":instance",scene_prop_rel_rot_x),
				(scene_prop_get_slot,":rel_rot_y",":instance",scene_prop_rel_rot_y),
				(position_move_x, pos30, ":rel_x"),
				(position_move_y, pos30, ":rel_y"),
				(position_move_z, pos30, ":rel_z"),
				(position_rotate_x, pos30, ":rel_rot_x"),
				(position_rotate_y, pos30, ":rel_rot_y"),
				# END RENDER #
				(prop_instance_set_position, ":instance", pos30),
				#(display_message, "@work"),
			(try_end),	# try for group members	 
		(try_end), # try for all groups
		]
)

common_tank_movement_1=(
	0, 0, 0, 
	[
		(key_clicked, key_v),
	],
	[
		(get_player_agent_no, ":p_agent"),
		(agent_get_position, pos0, ":p_agent"),
		(position_move_y, pos0, 500),
		(position_set_z, pos0, 10000),
		(position_set_z_to_ground_level, pos0),							
		# Rotate y
		(position_get_rotation_around_y,":tilt", pos0),
		(val_mul, ":tilt", -1),
		(position_rotate_y, pos0, ":tilt"),
		# Rotate y
		## Get spawn position
		(set_spawn_position, pos0),				
		(spawn_scene_prop, "spr_tank_body"),
		(assign, ":instance", reg0),
		(assign, "$elemate", ":instance"),
		(assign, ":instance_body", ":instance"),
		(call_script, "script_initialize_scene_prop_dynamics", ":instance", 0),
		(call_script, "script_set_scene_prop_abs_pos", ":instance"),
		(scene_prop_set_slot,":instance",scene_prop_set_z_ground,1),
		(scene_prop_set_slot,":instance",scene_prop_follow_slope,2),
		(scene_prop_set_slot,":instance",scene_prop_length,200),
		(scene_prop_set_slot,":instance",scene_prop_width,100),
		(position_move_z, pos0, 10, 1),
		(position_move_y, pos0, 15),
		(set_spawn_position, pos0),
		(spawn_scene_prop, "spr_turret"),
		(assign, ":instance", reg0),
		(assign, "$child", ":instance"),
		(call_script, "script_initialize_scene_prop_dynamics", ":instance", "$elemate"),
		(call_script, "script_set_scene_prop_abs_pos", ":instance"),
		(assign, "$spawned", 1),
		(mission_cam_set_mode, 1),
		(mission_cam_set_position, pos0),
		(try_begin),
			(neq,"$current_playing_sound","snd_tank_idle"),#Playing other sound
			(try_begin),
				(eq,"$current_player_sound",-1),#Playing no sound
				(prop_instance_stop_sound,":instance_body"),
				(prop_instance_play_sound,":instance_body","snd_tank_idle",sf_looping),
				(assign,"$current_playing_sound","snd_tank_idle"),
			(try_end),
		(try_end),
	]
)

common_tank_movement_2=(
		0, 0, 0, 
		[
			(eq,"$spawned",1),
		],
		[
		(try_begin),## Cam Position ##
			(gt, "$elemate", 0),			
			(call_script, "script_store_scene_prop_abs_pos_to_pos0", "$elemate"),
			(position_move_z, pos0, 500, 1),
			(position_move_y, pos0, -700),
			(position_rotate_x, pos0, -10),
			(mission_cam_set_position, pos0),
		(try_end),
		(try_begin),
			(gt, "$child", 0),
			(get_player_agent_no, ":p_agent"),
			(agent_get_look_position, pos0, ":p_agent"),
			(position_get_rotation_around_z, ":rot_z", pos0),
			(scene_prop_set_slot, "$child", scene_prop_rel_rot_z, ":rot_z"),
		(try_end),
		(try_begin),## Forward/Backward , Left/Right ##
			(gt, "$elemate", 0),
			(assign,":instance","$elemate"),
			(try_begin), 
				(key_is_down, key_u),
				(try_begin),
					(neq,"$current_playing_sound","snd_tank_moving"),#Playing other sound
					(try_begin),
						(eq,"$current_player_sound",-1),#Playing no sound
						(prop_instance_stop_sound,":instance"),
						(prop_instance_play_sound,":instance","snd_tank_moving",sf_looping),
						(assign,"$current_playing_sound","snd_tank_moving"),
					(try_end),
				(try_end),
				(scene_prop_set_slot,":instance",scene_prop_vel_abs_y,50),
			(else_try),	
				(key_is_down, key_j),
				(try_begin),
					(neq,"$current_playing_sound","snd_tank_moving"),#Playing other sound
					(eq,"$current_player_sound",-1),#Playing no sound
					(prop_instance_stop_sound,":instance"),
					(prop_instance_play_sound,":instance","snd_tank_moving",sf_looping),
					(assign,"$current_playing_sound","snd_tank_moving"),
				(try_end),
				(scene_prop_set_slot,":instance",scene_prop_vel_abs_y,-50),
			(else_try),	
				(scene_prop_set_slot,":instance",scene_prop_vel_abs_y,0),
				(prop_instance_stop_sound,":instance"),
				(assign,"$current_playing_sound",-1),
			(try_end),	
		(try_end), ## Forward/Backward , Left/Right ##	
		(try_begin),
			(key_is_down, key_h),
			(gt, "$elemate", 0),
			(assign,":instance","$elemate"),
			(call_script, "script_rot_scene_prop_group_z", ":instance", 10),
		(try_end),	
		(try_begin),
			(key_is_down, key_k),
			(gt, "$elemate", 0),
			(assign,":instance","$elemate"),
			(call_script, "script_rot_scene_prop_group_z", ":instance", -10),
		(try_end), ## Forward/Backward , Left/Right ##
		]
)

And here is my video test(no sound):


And i also post a video to my steam, you can watch it on my steam page
 
Namakan said:
You're using another model. Are you sure that you can rotate the turret with that thing(I think the "tank body" and the turret would have to be different parts of a multimesh/different meshes)
Yes, the tank body and the turret are the different meshes, and i make collision for them.
 
Namakan said:
You're using another model. Are you sure that you can rotate the turret with that thing(I think the "tank body" and the turret would have to be different parts of a multimesh/different meshes)
I have solved this problem, check this video:


He didn't add turret rotation code into the topic, just replace the original code with the following code:
...
######################################
# Step 3: Add oneself's rel. renders #
######################################
(scene_prop_get_slot,":rel_x",":instance",scene_prop_rel_pos_x),
(scene_prop_get_slot,":rel_y",":instance",scene_prop_rel_pos_y),
(scene_prop_get_slot,":rel_z",":instance",scene_prop_rel_pos_z),
(scene_prop_get_slot,":rel_rot_x",":instance",scene_prop_rel_rot_x),
(scene_prop_get_slot,":rel_rot_y",":instance",scene_prop_rel_rot_y),
(scene_prop_get_slot,":rel_rot_z",":instance",scene_prop_rel_rot_z),
(position_move_x, pos30, ":rel_x"),
(position_move_y, pos30, ":rel_y"),
(position_move_z, pos30, ":rel_z"),
(position_rotate_x, pos30, ":rel_rot_x"),
(position_rotate_y, pos30, ":rel_rot_y"),
(position_rotate_z, pos30, ":rel_rot_z"),
...
 
Back
Top Bottom