Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

minmay wrote: Sat Jul 07, 2018 1:45 am
akroma222 wrote:3. Can we define our own Collision Groups ?
No. Do you need more than 32 collision groups?
Nope! 32 Collision Groups should be sufficient :lol: 8-)
Thank you for your reply minmay, your explanation was *precisely* what I was looking for
Muchly appreciated :D :D
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

Is there a way to rotate objects upside down?
With this I mean as a simple example placing blooddrop cap upside down, making it look like it's hanging from the ceiling.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

Pompidom wrote: Sun Jul 08, 2018 11:10 am Is there a way to rotate objects upside down?
With this I mean as a simple example placing blooddrop cap upside down, making it look like it's hanging from the ceiling.
Yup, sure is...

Use this game object method to set (rotate actually) an object around its X, Y, Z axis

Code: Select all

GameObject:setWorldRotationAngles(x, y, z)
(x, y, z are number values between 0 and 360 degrees)

Use this method to raise an object to the ceiling (or lower it):

Code: Select all

GameObject:setWorldPositionY(y)
(y is how many in-game meters to raise or lower the object .. each grid square is 3m x 3m)

EDIT
It is possible to seemingly animate an object (just move it around and about)
by using the above :setWorldRotationAngles(x, y, z) method... to do so:
1. Timer (interval set to 0 or 0.0001) onActivate hook connected to a ....
2. Script entity (cubeAnimScript in this eg) with the following (or something similar) code:
SpoilerShow

Code: Select all

startHeight = 1.0
dir = 0
posY = 0

function cubeAnimator()
	
	local spinner = findEntity("akr_cube_block_1")
	
	if posY < startHeight then
		posY = posY + 0.001
		spinner:setPosition(cubeAnimScript.x, cubeAnimScript.y, dir, posY, cubeAnimScript.level)
	
	elseif posY >= startHeight then
		dir = dir + 0.02 %4
		posY = posY + 1.25 %.1
		spinner:setPosition(cubeAnimScript.x, cubeAnimScript.y, dir, (math.sin(posY) * 0.05 + 0.7), cubeAnimScript.level)
	end
end			
basically, every frame (60x/sec) the Timer is calling the cubeAnimator() function, which then alters the akr_cube_block's position and facing very very slightly ... this then makes the object appear to be animated (to the human eye ;-) )
Last edited by akroma222 on Sun Jul 08, 2018 5:35 pm, edited 2 times in total.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

The reason I asked, was I read about it in the Glügg sessions from Petri and I wanted to make a few rooms upside down after walking through a mirror. Now i can so thanx.

Sometimes it's a drag that I have 0 knowledge and even have to ask for the most basic commands, but once someone tells me about something new, I just use that knowledge to increase the detail and immersion on all my maps.

About the animation scripts, yes please do give me all the info you have. Yesterday I saw the dexterity door button puzzle. And I would love to experiment with it. For example skulls that turn around their axis :)
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

Edited my reply to include the (not really) animate object script (and how to)
EDIT: you dont need it but heres the def for akr_cube_block (use any object you like instead of)
SpoilerShow

Code: Select all

defineObject{
	name = "akr_cube_block",
	baseObject = "base_obstacle",
	components = {
		{
			class = "Model",
			model = "assets/models/items/vector_marker.fbx",		--LoG1 cube boss shell
			staticShadow = true,
		},
		{
			class = "Timer",
			name = "spintimer",
			timerInterval = 0.1,	--this is actually less than every frame
			triggerOnStart = true,
			onActivate = function(self)
				cubeAnimScript.script.cubeAnimator()
			end,
		},
	},
}
Pompidom wrote: Sun Jul 08, 2018 4:59 pm Sometimes it's a drag that I have 0 knowledge and even have to ask for the most basic commands, but once someone tells me about something new, I just use that knowledge to increase the detail and immersion on all my maps.
Everyone started at 0 modding knowledge :lol:
Most folk here are happy to assist, its quite a friendly forum (apparently!)
Try to find yourself a "Tome of Lua Ramblings", then consume it!
If you're a Human, your Modding skill will increase by 1 :D :lol:
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

This is looking very cool. I have floating skulls now :)
Also made some ceiling chandeliers turn around at a slow rate
And shops have pedestals with rotating items for sale :)

Exactly what I was looking for :)

How hard is it on the cpu cycles though? I probably shouldn't overdo it? :)
I put the timer on 0.1, which should probably lower the demand.

With this new script I'm going to make a hell dimension portal with 2 castle pillar candles slowly rotating to reveal a dark castle candle.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

akroma222 wrote: Sun Jul 08, 2018 3:30 pmbasically, every frame (60x/sec) the Timer is calling the cubeAnimator() function, which then alters the akr_cube_block's position and facing very very slightly ... this then makes the object appear to be animated (to the human eye ;-) )
A couple problems with the code you posted here:
1. You should use setWorldPosition(), not setPosition(), as the game expects elevation values (and x, y, facing values) to be integers.
2. You should multiply all the movement/rotation in this code by Time.deltaTime(), otherwise the cube moves faster at higher framerates and slower at lower ones.
Pompidom wrote: Sun Jul 08, 2018 5:49 pmHow hard is it on the cpu cycles though?
It's not. You would have to call setWorldPosition()/setWorldRotation()/setWorldRotationAngles()/etc. many thousands of times per frame for it to become a problem. You should just leave the timerInterval at 0 (which makes it always trigger once per frame).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

Good to know :)

Minmay, can you share us a simplified script where an object rotates at a certain worldposition spot slightly tilted using
setWorldRotationAngles()? I've tried some stuff, but I have no idea how to properly add worldrotationangles to the script.

https://ibb.co/fTvbmo

In this screenshot I have a bracelet spinning around with akroma's script. Since the bracelet's default position is already tilted, it looks like a great 3D animation. When doing this with let's say a health potion, the potion spins around but because it stands straight up in it's default position, it basically looks like nothing is happening. If I can tilt it with setWorldRotationAngles() while spinning it surely would improve things a lot.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

minmay wrote: Mon Jul 09, 2018 1:42 am 1. You should use setWorldPosition(), not setPosition(), as the game expects elevation values (and x, y, facing values) to be integers.
Yup! My error, mix up in translation
minmay wrote: Mon Jul 09, 2018 1:42 am 2. You should multiply all the movement/rotation in this code by Time.deltaTime(), otherwise the cube moves faster at higher framerates and slower at lower ones.
Ahhh I didnt know how to deal w that framerate issue yet, thanks!
This slowing down happens quite easily with a spell I created .... the spell - attempts :lol: - to recreate the attack swipe
in different patterns and angles etc. I could never manage to deal w the framerate issue :x so ive ignored it
I might repost about this shortly and see if Ive made the right corrections to the above code (and maybe spell).
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

Pompidom wrote: Mon Jul 09, 2018 12:42 pm Minmay, can you share us a simplified script where an object rotates at a certain worldposition spot slightly tilted using
setWorldRotationAngles()? I've tried some stuff, but I have no idea how to properly add worldrotationangles to the script.
Ok, same dealio - Timer (interval set to 0) onActivate hook connected to a Script with the following:
SpoilerShow

Code: Select all

manAnim_X = 0
manAnim_Y = 0
-----------------
function manualObjectAnimator()

	local cageObject = findEntity("prison_cage_1")
	local dT = Time.deltaTime()
	
	manAnim_X = manAnim_X + 1 % 360 * dT   		
	manAnim_Y = manAnim_Y + 0.25 % .1 * dT
	
	--TILT
	cageObject:setWorldRotationAngles(0, 10, 0)	          
	
	--ROTATE
	cageObject:setPosition(cageObject.x, cageObject.y, manAnim_X, (math.sin(manAnim_Y) * 0.02 + 0.1) * dT, cageObject.level)     
end
.... youll need a prison_cage_1 object obviously placed close by too :)
Post Reply