prop dynamics / physics help needed

Users who are viewing this thread

ithilienranger

Knight at Arms
I have been experimenting with some scene props, but I cannot use the new physics operations on them. How do I use these functions?

prop_instance_dynamics_set_properties  = 1871 # (prop_instance_dynamics_set_properties,<scene_prop_id>,mass_friction),
prop_instance_dynamics_set_velocity    = 1872 # (prop_instance_dynamics_set_velocity,<scene_prop_id>,linear_velocity),
prop_instance_dynamics_set_omega      = 1873 # (prop_instance_dynamics_set_omega,<scene_prop_id>,angular_velocity),
prop_instance_dynamics_apply_impulse  = 1874 # (prop_instance_dynamics_apply_impulse,<scene_prop_id>,impulse_force),
 
Sorry I can't help you with this, I have no clue how it works, but is it really that simple to add physics to any object or scene prop in Warband?!  :shock: 

That's going to be great fun to play with once it's all figured out.

I notice the ladder is set up like this, in module_scene_props:

check_ladder_animation_finish_trigger = (ti_on_scene_prop_animation_finished,
    [
      (store_trigger_param_1, ":instance_id"),

      (prop_instance_enable_physics, ":instance_id", 1),
      ])

And the box is set up like this:
("box_a_dynamic",sokf_moveable|sokf_dynamic_physics,"box_a","bo_box_a", []),

One or other of those two bolded commands are probably needed in the scene_props definition of your object, but you will know that already.  I don't know any more than that - it will probably boil down to trial and error.  Hopefully someone more familiar with the Warband module system will see this thread and help you out.



 
From the bugtracker:
Code:
("box_a_dynamic",sokf_moveable|sokf_dynamic_physics,"box_a","bo_box_a", [
	(ti_on_init_scene_prop, [
		(store_trigger_param_1, ":prop_instance_no"),
		(set_fixed_point_multiplier, 100),
		(position_set_x, pos0, 2500), #mass = 25.0
		(position_set_y, pos0, 80), #friction coefficient = 0.8
		(position_set_z, pos0, 0), #reserved variable
		(prop_instance_dynamics_set_properties, ":prop_instance_no", pos0),
		(position_set_x, pos0, 0),
		(position_set_y, pos0, 0),
		(position_set_z, pos0, 10000),
		(prop_instance_dynamics_set_omega, ":prop_instance_no", pos0), #spin around fast
		(position_set_x, pos0, 0),
		(position_set_y, pos0, 0),
		(position_set_z, pos0, 10000),
		(prop_instance_dynamics_apply_impulse, ":prop_instance_no", pos0), # and jump 
	]),
]),
 
("box_a_dynamic",sokf_moveable|sokf_dynamic_physics,"box_a","bo_box_a", []),
I guess I need the sokf_moveable|sokf_dynamic_physics flags, as well as prop_instance_enable_physics. I thought if I used prop_instance_enable_physics, then I wouldn't need the flag on the prop.

Thanks cmpxchg8b, that helps too. From the comments on the operations I thought the second parameter was a single value and not a 3D position.
 
I got the physics working on the props now. However, I cannot figure out how to dynamically change the movement direction for the impulse.

I was thinking something along the lines of this:

(get_player_agent_no, ":player_agent"),
(agent_get_look_position, pos1, ":player_agent"),
(position_copy_rotation, pos0, pos1),
(prop_instance_dynamics_apply_impulse, ":prop_instance_no", pos0),
 
It looks like the impulse_force positions variable is a force vector, so assuming the players rotation is normalized, you'd have to multiply it by the magnitude of the desired force (ie how much force you want in that direction).

I'll break down the bugtrackers example.

Code:
(position_set_x, pos0, 0),
      (position_set_y, pos0, 0),
      (position_set_z, pos0, 10000),
      (prop_instance_dynamics_apply_impulse, ":prop_instance_no", pos0), # and jump

Okay, so they wanted the box to jump, ie apply a force straight up and
it looks like they want to apply a force of 100 units (If you don't understand where I got this number, I'll explain later)

So they need the normalized vector <0,0,1>, for the straight-up direction.
Then to apply that force, they needed to multiply that by 100, which equals <0,0,100>
BUT the fixed point multiplier was set to 100, so they had to multiply it again by100 to compensate.
So we get <0,0,10000>. (10000/fixed point multiplier == 100 (the desired force))

So you just put those into the respective spots in the position and everything should work.

 
Yes, that's how to make an object jump straight up. However, I need to shoot a prop from the player's look position using the impulse. The problem that I am having is converting the get_look_position (which is a local position) to the impulse position (which is a global position).
 
Back
Top Bottom