How to reset object transforms using python?

Print “Hello world”
I am trying to reset object’s location XYZ to 0 when they are not equal 0 And not parented to any objects , how to perform that :thinking:
Print “thank you”

Hi,
maybe this can help:

import bpy

bpy.ops.object.location_clear()

If u want to reset:
location then use shortcut -> alt + g
scale then use shortcut -> alt + s
rotation then use shortcut -> alt + r

I have hope this help you.

If i changed .location to .rotation or .scale it will clear them right ?

Listen buddy , we are talking about the game engine right now , your answer is an answer for “how to use blender ui” ok ?

Listen buddy,
you’re currently on the python support section and not on the game engine one right now.
Your question is a question for “how to use the BGE” ok ?

1 Like

Hi Ahmad,
sorry, i didn’t know you talking about game engine …
i am not an expert :slight_smile:

1 Like

Anything involving the game engine needs to go in the game engine forum. There is a python section but that is for the python api as it applies to the blender interface - addons, tool scripts, etc. I notice you have a few other question in that forum for the game engine. That’s probably why you don’t get the responses you’re looking for.

As for your question, moving an object with python in the game engine is literally the first step in any introduction to using python in the game engine. I recommend you check out some tutorials. Look up Supergloop, Goran Milovanovic, TheTimster, Wayward Art on youtube.

# obj is your object - don't bother checking where it is, just move it
obj.worldPosition = 0,0,0
# or
obj.worldPosition.x = 0
obj.worldPosition.y = 0
obj.worldPosition.z = 0
# or
obj.worldPosition.zero()
1 Like

this is pretty simple to do

example ( includes Orientation and Scale)

import bge
cont = bge.logic.getCurrentController()

own = cont.owner

# Set object to world center 
own.worldPosition = [0,0,0]

# Set to default values
own.worldOrientation= [[1,0,0],[0,1,0],[0,0,1]]
own.worldScale = [1,1,1]
1 Like

orientation = mathutils.Matrix.Identity(3) little bit nicer i think.

1 Like

not nicer, just different.

and besides i wrote the example in a way so it would be more likely for a beginner not to get confused by anything.

while you’re at it you could just do

obj.worldOrientation.identity()

you also don’t get the point, it is not only about just setting identity, it is to show how you can set the orientation matrix to values you desire, an example would be you have stored orientation values in a save file and want to set it back on load.

1 Like