0
$\begingroup$

I have created a plane and I need to set the Physics Type of the object to NAVIGATION_MESH. I cant figure out, how I should do that. Below is the python script for generating this mesh and setting physics type but unfortunately its not working.

import bpy, mathutils

def create_custom_mesh(objname):
  # Define arrays for holding data 
  myvertex = []
  myfaces = []
  zcord = 11.83068 # Constant Z Coordinate

  # vertex 0
  mypoint = [(-4.64863, -4.80997, zcord)]
  myvertex.extend(mypoint)
  # vertex 1
  mypoint = [(-4.02263, -4.80997, zcord)]
  myvertex.extend(mypoint)
  # vertex 2
  mypoint = [(-4.64863, -4.18397, zcord)]
  myvertex.extend(mypoint)
  # vertex 3
  mypoint = [(-4.02263, -4.18397, zcord)]
  myvertex.extend(mypoint)

  myface = [(0, 1, 3, 2)]
  myfaces.extend(myface)   
  # Create mesh data      
  mymesh = bpy.data.meshes.new(objname)
  # Create object
  myobject = bpy.data.objects.new(objname, mymesh)

  # Link object to scene
  bpy.context.scene.objects.link(myobject)
  # Generate mesh data
  mymesh.from_pydata(myvertex, [], myfaces)
  # Calculate the edges
  mymesh.update(calc_edges=True)
  return myobject

create_custom_mesh("route_plane")
bpy.data.objects['route_plane'].select = True
bpy.data.objects['route_plane'].game.physics_type == 'NAVIGATION_MESH'
print("---------------------------------------------")

What am I making wrong here, cause the object 'route_plane' gets created and being placed at the correct location in the scene but physics type is never set. I need to set the "Navigation Mesh" physics type on an existing object, like 'route_plane' (as in the above code). I can not generate the navigation mesh via the relevant button in the scene properties using GUI.

Please help me, thanks in advance !

$\endgroup$
1
$\begingroup$

The enum for a navigation mesh is 'NAVMESH' not 'NAVIGATION_MESH'. The python console is your friend here.

>>> C.object.game.physics_type = 'SOMETHING_WRONG'
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: bpy_struct: item.attr = val: enum "SOMETHING_WRONG" not found in ('NO_COLLISION', 'STATIC', 'DYNAMIC', 'RIGID_BODY', 'SOFT_BODY', 'OCCLUDER', 'SENSOR', 'NAVMESH', 'CHARACTER')

You weren't getting an error because you had the double equals == which is a boolean test

game.physics_type == 'NAVIGATION_MESH'

Which will equate to False, more commonly I make the mistake of one equals, if (x=y) lol.

$\endgroup$
  • $\begingroup$ I dont know why I make such stupid mistakes (double equals '=='), but anyway that fixed my problem, with the enum. I owe you a drink man !! Thanks a lot. $\endgroup$ – sosoup Sep 24 '15 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.