PDA

View Full Version : A way to make the Whizzle character teleport?



Lait
11-29-2009, 11:47 PM
Hey, I'm trying to create a way to make the Whizzle character teleport to a new location. This is my Tick() function:


simulated event Tick(float DT)
{
local vector destination;
super.Tick(DT);

//Create an arbitrary destination to teleport to
destination.X = 0;
destination.Y = 120;
destination.Z = 500;

//Teleport to the destination
TeleportTo(destination);
}

Basically, when Tick() is called, the Whizzle character should teleport to the destination. I know this code is kinda silly - once the Whizzle character teleports the first time it will keep teleporting to the same destination. Also recreating the same teleport destination every time Tick() is called is also silly.

This is my TeleportTo() function:

simulated function TeleportTo(vector destination)
{
//To teleport, just set our location to the destination?
//This doesn't seem to work, though.
SetLocation(destination);
}

The problem is that this function doesn't move the Whizzle character. The Whizzle character just stays in place. If I set a few log commands around TeleportTo(), though, I find that the location does, in fact, change. However, the location reverts back before Tick() is called again! Basically, the teleport works, but the location is reset each time, so the teleport has no effect. If you guys want, I can post the rest of my source code if you think the problem is unrelated to the code that I posted.

Basically, does anyone know of a way to teleport the Whizzle character to a new location?

Psyonix-Jerad
11-30-2009, 03:20 PM
That's because it is physics driven, and SetLocation won't work on objects that are PHYS_RigidBody, because the physics body is what is controlling the location of the Actor. Try having a look at SVehicle.PostTeleport to see what you should do in the case of physics.

Psyonix-Jerad
11-30-2009, 03:23 PM
...Also there is a whole slew of classes that handle teleporting, you only need to implement the proper functions to make that feature work for the Whizzle character.

Psyonix-Dave
11-30-2009, 04:01 PM
Also keep in mind the character is made of two actors... the AquaBall, which is invisible but has rigidbody collision, and the AquaCharacter which does not have collision itself but is attached to the Aquaball by a rigidbody joint. This happens in the PostBeginPlay event of the AquaBall which executes the SpawnCharacter() function.

Teleporting just the AquaBall might work out, but I would expect problems with the joint flipping out due to the instant change in position. You probably want to teleport both at the same time and use SetRBPosition on the Meshes after you do a set position on the Actor itself.

Lait
11-30-2009, 06:42 PM
Alright, I wasn't aware what PHYS_RigidBody did exactly, but that would explain why I can't just move it to any place I want -- I need to use an impulse or force of some kind. Anyways, for a quick fix I put "SetPhysics(PHYS_Flying);" in PostBeginPlay(), and TeleportTo() works now. This of course makes everything else about the AqualBall not work as intended, so I'll look into how vehicles are teleported to see how to correctly teleport physics objects.

I'm trying to use Whizzle to figure out how everything in the engine works in general, and so far the source code and the creation document have been really useful. Thanks for the prompt response!

Sarcen
12-01-2009, 11:36 PM
CollisionComponent.SetRBLocation() will have effect.