Having trouble rotating collision shapes

So. I used the flipv and fliph commands, and they worked! But…i’m using a rectangular hit box that’s for detecting/interacting with other objects when you press Z. The game i’m working on is a top down style RPG, and so i need something along those lines to interact with NPCs, and inspect objects, etc.
But. You remember how i’m trying to flip a rectangle? It works vertically! And Technically works horizontally too. But i want it to flip in such a way that it sticks out from the player in the direction they’re facing. So instead of trying to flip the box, i’m trying to to change it’s dimensions and position when the player uses the arrow keys. I’ve tried a bunch of different ways to get this to work. And i keep getting this error:

ERROR:SCRIPT: My stuff/Player/player-scripts/player interaction.script:1: attempt to call global ‘get_position’ (a nil value)
stack traceback:
My stuff/Player/player-scripts/player interaction.script:1: in main chunk

WARNING:RESOURCE: Unable to create resource: /My stuff/Player/player-scripts/player interaction.scriptc: FORMAT_ERROR
WARNING:RESOURCE: Unable to create resource: /_generated_76a803e.goc: FORMAT_ERROR
ERROR:GAMEOBJECT: Could not instantiate game object from prototype /_generated_76a803e.goc.
WARNING:RESOURCE: Unable to create resource: /main/main.collectionc: FORMAT_ERROR

can someone with more experience help me out please?

Any help, as always is very much appreciated :slight_smile:

Here’s the script for reference:

local pos = get_position("player#collisionobject")
local position = vmath.vector3(x, y, z)()

function init(self)
	msg.post(".", "acquire_input_focus")
	position = vmath.vector3()
end

function on_input(self, action_id, action)
	if action_id == hash("up") then
		set_position(y,13, x,0.5)
		set_rotation(z,0)
	elseif action_id == hash("down") then
		set_position(y,13, x,0.5)
		set_rotation(z,0)
	elseif action_id == hash("left") then
		set_position(y,13, x,0.5)
		set_rotation(z,90)
	elseif action_id == hash("right") then
		set_position(y,13, x,0.5)
		set_rotation(z,90)
	end
end

Also BTW i didn’t use go.set_position. because Defold kept letting me know that go. was just for globals

Also i did think about possibly doing something similar with ray casting instead of a collision shape. would that work?

Do you have a function called get_position(), if not, it’s going to be nil, hence your error.

And correct, you must use go.get_position() from within the life cycle functions.

1 Like

Thanks man!

There is some documentation here:

2 Likes

Awesome, Thanks for the link!
i’m still to learning Lua, and just how to script in general. And i’ve still got a long way to go before i can write something that doesn’t initially have about 40 different things wrong with it XD, so i’m definitely going to be reading up on this in particular. Because it seems like something i should have probably already known by now.

Also thank you for always answering my midnight questions XD