Let's Build! #1 - Make a Tornado Dash Ability

Join me in a one-hour Discord stream where we build something based on the community’s prompt! It can be art, UI or a mechanic inspired by another game – or just something that you would like to implement in your game and that is not yet in the Community Content. Come pitch the idea and I’ll stream making it, along with answering questions about scripting.

The goals of these sessions are to:

  • Learn how to build things in Core by looking at someone else.
  • Answer your questions while making the content.
  • Publish the content created during the stream in the Community Content.

The sessions are intended for beginners but advanced creators who want to learn to script will find value as well. An assignment for the next week will be given at the end of the stream for people that want to try by themselves.

Next session: Monday at 10am PT (7pm CEST)
Where: Creators Discord, Voice channel #Event-Moderated
Who: caillef

See you all on Monday :wave:

2 Likes

27 Sept. 2021

Goal of this session

Make a Tornado Ability that makes the player dash in front of him.
tornado

What we covered

  • Ability and Equipment
  • Spawn an Object
  • Script an Ability
  • VFX and SFX for a Tornado
  • Lua Good Practices: Constants and Custom Properties
  • Damageable Objects
  • Add Resource and Resource Display

Replay

Timecodes of each part

0:00 - Equip an Ability when the player joins
4:38 - Testing and Prototyping: Looking for a solution to move the player
13:20 - Planning the solution
14:29 - Spawn an object
17:50 - Attach a player to a moving object
20:57 - Constants in Lua and Custom Properties
25:34 - Add Tornado VFX in Client Context
27:18 - Trying to change the system but rolling back
33:19 - Find the destination of the dash (Forward and Transform)
36:19 - Polish code, SFX, player animation
51:35 - DamageableObject Crates
59:26 - AddResource Gems when breaking Crates

Template of the system

PBT file (drop it in your Core window and then drag and drop the template TornadoGame in your scene)
Left-click to use the Tornado Dash Ability

Main script

I had to fix two bugs after the live:

  • Use FindDescendant and not FindChild to find the Tornado as it is a child of TornadoGame by default (this can be enhanced by doing the second basic challenge given just above)
  • Sometimes the dash was not in the correct direction because I was looking at the transform after attaching the player to the object, which was changing the rotation in a specific direction. A comment has been added to explain what changed.
(click to open) Main Script - AbilityDash
local ABILITY = script.parent
-- BUG FIX: this method to find the Tornado is not great because it is only working for one player
-- I changed FindChild to FindDescendant because the tornado is by default in the group TornadoGame
local TORNADO = World.GetRootObject():FindDescendantByName("Tornado")
local TORNADO_DURATION = ABILITY:GetCustomProperty("TornadoDuration")
local TORNADO_RANGE = ABILITY:GetCustomProperty("TornadoRange")

function ConnectAbilityEvents_TornadoDash(ability)
	ability.castEvent:Connect(OnCast_TornadoDash)
	ability.executeEvent:Connect(OnExecute_TornadoDash)
end

function OnCast_TornadoDash(ability)
	local player = ability.owner
	local playerPos = player:GetWorldPosition()
	TORNADO:SetWorldPosition(playerPos)
	TORNADO:SetScale(Vector3.ZERO)
	TORNADO.visibility = Visibility.FORCE_ON
	TORNADO:ScaleTo(Vector3.ONE, 0.2)
	-- BUG FIX: this line is moved to line 26 because it was modifying
	-- the transform of the player so the dash was not based on the player direction
	-- player:AttachToCoreObject(TORNADO)
end

function OnExecute_TornadoDash(ability)
	local player = ability.owner
	local forward = player:GetWorldTransform():GetForwardVector()

	player:AttachToCoreObject(TORNADO)

	local finalVector = player:GetWorldPosition() + forward * TORNADO_RANGE
	TORNADO:MoveTo(finalVector, TORNADO_DURATION)

	Task.Wait(TORNADO_DURATION)
	player:Detach()
	TORNADO.visibility = Visibility.FORCE_OFF
end

ConnectAbilityEvents_TornadoDash(ABILITY)

Challenges

Basic challenges

  • Enable the Trigger that destroy the crates only during the dash (currently you can just walk and destroy crates, you will have to toggle the collision of the Trigger at the right place)
  • Instead of using FindDescenntByName to find the Tornado, spawn one Tornado per player and store the object reference of that Tornado somewhere (maybe ABILITY.serverUserData.tornado = TORNADO?)
  • More explosion and feedback to the player

Advanced challenge

  • Make a game that reaches 200+ plays with the tornado dash as the main mechanic.
5 Likes