This is the first time that I am writing here, trying to seek help on a problem that I have.
The set up is a just a top-down camera, with the screen divided in two, and each side contains one character. The intent is that the player will control both characters at the same time. That I’ve managed to accomplished.
What I can’t get my head around is that when one of the characters collide with a wall, the other character will also stop moving (at least not being able to move past that wall, as if the wall was there as well) even if it is not touching any wall.
I tried making then children objects of a parent empty object, tried boolean control, but then can’t reverse back.
I’m a noob when it comes to programming, so bare that in mind.
If anyone can shed any light is greatly appreciated.
The characters are going to be just a cube, and there is no character controller. The movement is being done with a simple transform.Translate(x,0,z) based on Input from “Horizontal” and “Vertical” axis.
They both respond to the same controls (to the point I was assigning the same script to both characters).
Currently I am not making them parents from one another because the influence works both ways. If cube1 touches a wall, cube2 stops moving too and vice-versa.
The best way to show it, is that what I am trying to accomplish is pretty much the same as the game “Hello Worlds!” at Armorgames website. There, the character in one screen is directly influence by the wall on the “parallel universe” as if the wall was there.
Ah, I think I get it - I thought you were saying the fact that one character stops when the other runs into a wall was the problem, but you’re saying that’s actually the behavior you’re trying to achieve. Is that right?
It is indeed. I want the other to stop when the first hits the wall. But not completely stop, as if the first walks along the wall, the second will also follow.
In other words, follow every move as if it was a mirror.
How are you doing the collision detection? Are you using colliders/rigid bodies? (I ask because you said you’re moving the objects by modifying the transform directly, so I’m wondering if you’re doing the collision detection manually as well.)
I am using rigidbody in the characters with collision boxes for the walls.
The script I worked that does “almost” what I want is this one.
var speed : int = 5;
function FixedUpdate () {
var x = Input.GetAxis(“Horizontal”) * Time.deltaTime * speed;
var z = Input.GetAxis(“Vertical”) * Time.deltaTime * speed;
transform.Translate(x,0,z);
transform.Rotate(0,0,0);
function FixedUpdate () {
var x = Input.GetAxis(“Horizontal”) * Time.deltaTime * speed;
var z = Input.GetAxis(“Vertical”) * Time.deltaTime * speed;
transform.Translate(x,0,z);
transform.Rotate(0,0,0);
It works more or less to what I want, because when one his the wall, both character start to go extremely slow. But then I lose the possibility of having the movement of “walking” along the wall.
If I put the speed to zero, the same happens, and I can’t even move after touching a wall.
With that very simple step, it did work as I wanted!
Thank you so much for the suggestion.
For the situation where for a short time only one will move, and then when the “link” is restored, it would be something like breaking the fixed joint, moving the character, and then re-linking the fixed joint in the new position, right? Can I programme this? (I’m a noob, remember?) :?
i.e. → On picking an item {break fixed joint - stop moving character 1 for 5 seconds - after which, restore fixed joint}
I found breakForce and breakTorque, but not sure if those can help me.
Not having tried it myself, I can’t say for sure, but I’d be surprised if it couldn’t be done. IIRC, joints are components that have a ‘target rigid body’ field, so I’d imagine you could set one up in code just like you’d set up any other type of component.